Commit Graph

13569 Commits

Author SHA1 Message Date
Seth Webster
ebb2253428
updates mailmap entries (#19824) 2020-09-12 13:05:52 -04:00
Dan Abramov
cc581065df eslint-plugin-react-hooks@4.1.2 2020-09-11 13:18:44 +01:00
Dan Abramov
0044805c88
Update CHANGELOG.md 2020-09-11 13:17:55 +01:00
Sebastian Silbermann
0f70d4dd66
Consider components in jsx as missing dependencies in @typescript-eslint/parser@4.x (#19815)
* Run JS tests with TS esling parser

* Add failing test

* fix: Mark JSXIdentifier has missing dependency

* Safe isSameIdentifier
2020-09-11 13:13:43 +01:00
Andrew Clark
84558c61ba
Don't visit passive effects during layout phase (#19809)
Removes the `Update` flag when scheduling a passive effect for
`useEffect`. The `Passive` flag alone is sufficient.

This doesn't affect any behavior, but does optimize the performance of
the commit phase.
2020-09-10 14:00:41 -07:00
Dan Abramov
ad8a0a8cd0 eslint-plugin-react-hooks@4.1.1 2020-09-10 19:54:42 +01:00
Dan Abramov
77544a0d6f
Update CHANGELOG.md 2020-09-10 19:54:10 +01:00
Sebastian Silbermann
ed4fdfc737
test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x (#19792)
* test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x

* name test suites for each parser
2020-09-10 19:08:47 +01:00
Matthias Schiffer
cd75f93c03
eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/parser@4.0.0+ (#19751)
In addition to `TSTypeQuery`, dependency nodes with a `TSTypeReference`
parent need to be ignored as well. Without this fix, generic type
variables will be listed as missing dependencies.

Example:

    export function useFoo<T>(): (foo: T) => boolean {
        return useCallback((foo: T) => false, []);
    }

This will report the following issue:

    React Hook useCallback has a missing dependency: 'T'. Either include
    it or remove the dependency array

Closes: #19742
2020-09-10 11:30:18 +01:00
Dan Abramov
a08ae9f147
Listen to onScroll during hydration (#19803) 2020-09-10 11:00:02 +01:00
Gustavo Saiani
781212aab3
Remove double space in test name (#19762) 2020-09-09 18:26:44 -04:00
Andrew Clark
e7b255341b
Internal act: Flush timers at end of scope (#19788)
If there are any suspended fallbacks at the end of the `act` scope,
force them to display by running the pending timers (i.e. `setTimeout`).

The public implementation of `act` achieves the same behavior with an
extra check in the work loop (`shouldForceFlushFallbacks`). Since our
internal `act` needs to work in both development and production, without
additional runtime checks, we instead rely on Jest's mock timers.

This doesn't not affect refresh transitions, which are meant to delay
indefinitely, because in that case we exit the work loop without
posting a timer.
2020-09-08 21:55:23 -07:00
Andrew Clark
d17086c7c8
Decouple public, internal act implementation (#19745)
In the next major release, we intend to drop support for using the `act`
testing helper in production. (It already fires a warning.) The
rationale is that, in order for `act` to work, you must either mock the
testing environment or add extra logic at runtime. Mocking the testing
environment isn't ideal because it requires extra set up for the user.
Extra logic at runtime is fine only in development mode — we don't want
to slow down the production builds.

Since most people only run their tests in development mode, dropping
support for production should be fine; if there's demand, we can add it
back later using a special testing build that is identical to the
production build except for the additional testing logic.

One blocker for removing production support is that we currently use
`act` to test React itself. We must test React in both development and
production modes.

So, the solution is to fork `act` into separate public and
internal implementations:

- *public implementation of `act`* – exposed to users, only works in
  development mode, uses special runtime logic, does not support partial
  rendering
- *internal implementation of `act`* – private, works in both
  development and productionm modes, only used by the React Core test
  suite, uses no special runtime logic, supports partial rendering (i.e.
  `toFlushAndYieldThrough`)

The internal implementation should mostly match the public
implementation's behavior, but since it's a private API, it doesn't have
to match exactly. It works by mocking the test environment: it uses a
mock build of Scheduler to flush rendering tasks, and Jest's mock timers
to flush Suspense placeholders.

---

In this first commit, I've added the internal forks of `act` and
migrated our tests to use them. The public `act` implementation is
unaffected for now; I will leave refactoring/clean-up for a later step.
2020-09-08 08:11:45 -07:00
Joseph Savona
d38ec17b1d
[Flight] Set dispatcher for duration of performWork() (#19776) 2020-09-07 19:41:22 -04:00
Andrew Clark
4f3f7eeb7f
Bugfix: Effect clean up when deleting suspended tree (#19752)
* Bug: Effect clean up when deleting suspended tree

Adds a failing unit test.

* Re-use static flags from suspended primary tree

When switching to a Suspense boundary's fallback, we need to be sure
to preserve static subtree flags from the primary tree.
2020-09-04 15:46:44 -07:00
Andrew Clark
7baf9d4128
Combine Flags and SubtreeFlags types (#19775)
Because the `subtreeFlags` is the union of all the flags present in
a subtree, we can use the same type as `flags`.

One practical benefit is that we can bubble up the flags from the
children with a single `|=` operator.

Structurally, everything else about the effect algorithm is unchanged.
2020-09-04 14:48:30 -07:00
Andrew Clark
1665443603
Rename effect fields (#19755)
- `effectTag` -> `flags`
- `subtreeTag` -> `subtreeFlags`
2020-09-04 14:34:07 -07:00
Andrew Clark
708fa77a78
Decrease expiration time of input updates (#19772)
Changes the expiration time of input updates from 1000ms to 250ms, to
match the corresponding constant in Scheduler.js.

When we made it larger, a product metric in www regressed, suggesting
there's a user interaction that's being starved by a series of
synchronous updates. If that theory is correct, the proper solution is
to fix the starvation. However, this scenario supports the idea that
expiration times are an important safeguard when starvation does happen.

Also note that, in the case of user input specifically, this will soon
no longer be an issue because we plan to make user input synchronous by
default (until you enter `startTransition`, of course.)

If weren't planning to make these updates synchronous soon anyway, I
would probably make this number a configurable parameter.
2020-09-04 10:42:09 -07:00
Ricky
36df483af4
Add feature flag to disable scheduler timeout in work loop (#19771) 2020-09-04 10:58:17 -04:00
E-Liang Tan
eabd18c73f
Scheduling Profiler: Move preprocessing to web worker and add loading indicator (#19759)
* Move preprocessData into a web worker
* Add UI feedback for loading/import error states
* Terminate worker when done handling profile
* Add display density CSS variables
2020-09-04 10:57:32 -04:00
E-Liang Tan
38a512acad
Scheduling Profiler: Redesign with DevTools styling (#19707)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-03 12:08:40 -04:00
Dan Abramov
bcc0aa4633
Revert "Revert "Remove onScroll bubbling flag (#19535)" (#19655)" (#19761)
This reverts commit 64ddef44c6.
2020-09-03 17:06:20 +01:00
E-Liang Tan
e9454894ff
Scheduling Profiler: Extract and test scroll state from horizontal pan and zoom view (#19682)
* Extract reusable scroll logic from HorizontalPanAndZoomView

* Change VerticalScrollView to use scrollState

* Clarify test name
2020-09-03 10:27:35 -04:00
E-Liang Tan
9340083395
Scheduling Profiler: Add Fast Refresh (#19757) 2020-09-03 09:17:57 -04:00
Meghnath Pillay
835c11eba7
Add checkbox toggle for boolean values (#19714)
* added a checkbox which appears to the right of a value when value is boolean
* checkbox with toggle capability created for boolean props

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-09-03 08:57:12 -04:00
Brian Vaughn
99cae887f3
Add failing test for passive effect cleanup functions and memoized components (#19750)
* Add failing tests for passive effects cleanup not being called for memoized components

* Bubble passive static subtreeTag even after bailout

This prevents subsequent unmounts from skipping over any pending passive effect destroy functions
2020-09-02 13:01:52 -04:00
Ikko Ashimine
2cfd73c4d0
Fix typo in comment (Noticable→Noticeable) (#19737) 2020-09-01 20:19:10 -04:00
Brian Vaughn
98dba66ee1
Add ⎇ + arrow key navigation to DevTools (#19741)
⎇ + left/right navigates between owners (similar to owners tree) and ⎇ + up/down navigations between siblings.
2020-09-01 20:03:44 -04:00
Bhumij Gupta
53e622ca7f
Fix instances of function declaration after return (#19733)
* Add ESLint plugin to check for any function declare after return
* Refactor code to move function declarations before return and fix failing lint
2020-09-01 08:55:10 -04:00
Kevin Weber
b7d18c4daf
Support Babel's envName option in React Refresh plugin (#19009)
* Fix envName bug

* Replace getEnv with env
2020-09-01 13:50:54 +01:00
Andrew Clark
1f38dcff67
Remove withSuspenseConfig (#19724)
Removes `withSuspenseConfig` and migrates relevant tests to
`startTransition` instead.

We only had one caller in www, which I've removed.
2020-08-31 09:16:49 -07:00
Pascal Fong Kye
1396e4a8f5
Fixes eslint warning when node type is ChainExpression (#19680)
* Add babel parser which supports ChainExpression

* Add and fix tests for new babel eslint parser

* extract function to mark node

* refactor for compatibility with eslint v7.7.0+

* Update eslint to v7.7.0
Update hook test since eslint now supports nullish coalescing
2020-08-29 21:03:23 +01:00
Andrew Clark
a8500be893
Add startTransition as a known stable method (#19720)
The `startTransition` method returned from `useTransition` is a stable
method, like `dispatch` or `setState`. You should not have to specify
it as a hook dependency.
2020-08-28 16:44:39 -07:00
Andrew Clark
4f5fb56100
Use gate pragma instead of if (__EXPERIMENTAL__) (#19722)
* Use gate pragma instead of if (__EXPERIMENTAL__)

* Fix stream error handling in tests

Added an error listener so that the tests fail within their Jest scope,
instead of crashing the whole process.
2020-08-28 14:21:01 -07:00
Timothy Yung
380dc95de8
Revert "Append text string to <Text> error message (#19581)" (#19723)
This reverts commit 1a41a196bc.
2020-08-28 13:46:59 -07:00
Andrew Clark
ddd1faa197
Remove config argument from useTransition (#19719)
And `useDeferredValue`.

The options were already disabled in previous commits, so this doesn't
change any behavior. I upated type signatures and cleaned up the hook
implementation a bit — no longer have to wrap the `start` method with
`useCallback`, because its only remaining dependency is a `setState`
method, which never changes. Instead, we can store the `start` method
on a ref.
2020-08-28 11:49:01 -07:00
Andrew Clark
92fcd46cc7
Replace SuspenseConfig object with an integer (#19706)
Now that the options in SuspenseConfig are no longer supported, the
only thing we use it for is to track whether an update is part of
a transition.

I've renamed `ReactCurrentBatchConfig.suspense` to
`ReactCurrentBatchConfig.transition`, and changed the type to a number.
The number is always either 0 or 1. I could have made it a boolean;
however, most likely this will eventually be either a Lane or an
incrementing identifier.

The `withSuspenseConfig` export still exists until we've removed
all the callers from www.
2020-08-28 10:52:56 -07:00
Dan Abramov
b754caaaf2
Enable eager listeners in open source (#19716)
* Enable eager listeners in open source

* Fix tests

* Enable in all places
2020-08-28 12:23:28 +01:00
Dan Abramov
c1ac052158
[Flight] Support more element types and Hooks for Server and Hybrid Components (#19711)
* Shim support for more element types

* Shim commonly used Hooks that are safe

* Flow

* Oopsie
2020-08-27 20:19:13 +01:00
Andrew Clark
1eaafc9ade
Clean up timeoutMs-related implementation details (#19704)
* Disable busyDelayMs and busyMinDurationMs

Refer to explanation in previous commit.

* Remove unnecessary work loop variables

Since we no longer support SuspenseConfig options, we don't need to
track these values.

* Remove unnecessary Update fields
2020-08-27 09:47:58 -07:00
Andrew Clark
8da0da0937
Disable timeoutMs argument (#19703)
* Remove distinction between long, short transitions

We're removing the `timeoutMs` option, so there's no longer any
distinction between "short" and "long" transitions. They're all treated
the same.

This commit doesn't remove `timeoutMs` yet, only combines the internal
priority levels.

* Disable `timeoutMs` argument

tl;dr
-----

- We're removing the `timeoutMs` argument from `useTransition`.
- Transitions will either immediately switch to a skeleton/placeholder
  view (when loading new content) or wait indefinitely until the data
  resolves (when refreshing stale content).
- This commit disables the `timeoutMS` so that the API has the desired
  semantics. It doesn't yet update the types or migrate all the test
  callers. I'll do those steps in follow-up PRs.

Motivation
----------

Currently, transitions initiated by `startTransition` / `useTransition`
accept a `timeoutMs` option. You can use this to control the maximum
amount of time that a transition is allowed to delay before we give up
and show a placeholder.

What we've discovered is that, in practice, every transition falls into
one of two categories: a **load** or a **refresh**:

- **Loading a new screen**: show the next screen as soon as possible,
  even if the data hasn't finished loading. Use a skeleton/placeholder
  UI to show progress.
- **Refreshing a screen that's already visible**: keep showing the
  current screen indefinitely, for as long as it takes to load the fresh
  data, even if the current data is stale. Use a pending state (and
  maybe a busy indicator) to show progress.

In other words, transitions should either *delay indefinitely* (for a
refresh) or they should show a placeholder *instantly* (for a load).
There's not much use for transitions that are delayed for a
small-but-noticeable amount of time.

So, the plan is to remove the `timeoutMs` option. Instead, we'll assign
an effective timeout of `0` for loads, and `Infinity` for refreshes.

The mechanism for distinguishing a load from a refresh already exists in
the current model. If a component suspends, and the nearest Suspense
boundary hasn't already mounted, we treat that as a load, because
there's nothing on the screen. However, if the nearest boundary is
mounted, we treat that as a refresh, since it's already showing content.

If you need to fix a transition to be treated as a load instead of a
refresh, or vice versa, the solution will involve rearranging the
location of your Suspense boundaries. It may also involve adding a key.

We're still working on proper documentation for these patterns. In the
meantime, please reach out to us if you run into problems that you're
unsure how to fix.

We will remove `timeoutMs` from `useDeferredValue`, too, and apply the
same load versus refresh semantics to the update that spawns the
deferred value.

Note that there are other types of delays that are not related to
transitions; for example, we will still throttle the appearance of
nested placeholders (we refer to this as the placeholder "train model"),
and we may still apply a Just Noticeable Difference heuristic (JND) in
some cases. These aren't going anywhere. (Well, the JND heuristic might
but for different reasons than those discussed above.)
2020-08-26 14:35:13 -07:00
Ben Pernick
60ba723bf7
Add SuspenseList to devTools (#19684)
* ensure getDisplayName is only called on functions

* add SuspenseList to Dev tools element names

* Add SuspenseList and pass tests

* Import SuspenseList directly

* run prettier

* Refactor tests to use real components

* run linter
2020-08-26 18:04:43 +01:00
Ricky
5564f2c95b
Add React.startTransition (#19696)
* Add React.startTransition

* Export startTransition from index.js as well
2020-08-26 11:34:17 -04:00
inottn
c4e0768d74
Remove unused argument from finishConcurrentRender (#19689) 2020-08-25 13:49:57 +01:00
Andrew Clark
af219cc6e6
Lint rule to forbid access of cross-fork fields (#19679)
* Lint rule to forbid access of cross-fork fields

We use a shared Fiber type for both reconciler forks (old and new). It
is a superset of all the fields used by both forks. However, there are
some fields that should only be used in the new fork, and others that
should only be used in the old fork.

Ideally we would enforce this with separate Flow types for each fork.
The problem is that the Fiber type is accessed by some packages outside
the reconciler (like React DOM), and get passed into the reconciler as
arguments. So there's no way to fork the Fiber type without also forking
the packages where they are used. FiberRoot has the same issue.

Instead, I've added a lint rule that forbids cross-fork access of
fork-specific fields. Fields that end in `_old` or `_new` are forbidden
from being used inside the new or old fork respectively. Or you can
specific custom fields using the ESLint plugin options.

I used this plugin to find and remove references to the effect list
in d2e914a.

* Mark effect list fields as old

And `subtreeTag` as new.

I didn't mark `lastEffect` because that name is also used by the
Hook type. Not super important; could rename to `lastEffect_old` but
idk if it's worth the effort.
2020-08-24 10:07:11 -07:00
Dan Abramov
848bb2426e
Attach Listeners Eagerly to Roots and Portal Containers (#19659)
* Failing test for #19608

* Attach Listeners Eagerly to Roots and Portal Containers

* Forbid createEventHandle with custom events

We can't support this without adding more complexity. It's not clear that this is even desirable, as none of our existing use cases need custom events. This API primarily exists as a deprecation strategy for Flare, so I don't think it is important to expand its support beyond what Flare replacement code currently needs. We can later revisit it with a better understanding of the eager/lazy tradeoff but for now let's remove the inconsistency.

* Reduce risk by changing condition only under the flag

Co-authored-by: koba04 <koba0004@gmail.com>
2020-08-24 16:50:20 +01:00
Dominic Gannaway
8c9fc4e90f
Remove usage of PossiblyWeakSet from createEventHandle (#19686) 2020-08-24 16:10:23 +01:00
Toru Kobayashi
2ada4bd0c2
Add a test for non-passive event handlers for events affected by the browsers' intervention (#19658) 2020-08-24 14:30:17 +01:00
Andrew Clark
d2e914ab4e
Remove remaining references to effect list (#19673)
* Remove `firstEffect` null check

This is the last remaining place where the effect list has semantic
implications.

I've replaced it with a check of `effectTag` and `subtreeTag`, to see
if there are any effects in the whole tree. This matches the semantics
of the old check. However, I think only reason this optimization exists
is because it affects profiling. We should reconsider whether this
is necessary.

* Remove remaining references to effect list

We no longer use the effect list anywhere in our implementation. It's
been replaced by a recursive traversal in the commit phase.

This removes all references to the effect list in the new fork.
2020-08-21 20:42:32 -05:00
Brian Vaughn
0386bd0da2
Tweaked landing page styles (#19665)
* Tweaked landing page styles

* Update GitHub link

Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2020-08-21 14:06:01 -04:00