Commit Graph

11101 Commits

Author SHA1 Message Date
Dominic Gannaway e6bfa327da [Flare] Cleanup ReactFiberEvents-test (#16047) 2019-07-03 11:31:06 +01:00
Dominic Gannaway b365ee2816 [Fire] Remove unused React fire fork (#16046) 2019-07-03 11:05:28 +01:00
Sunil Pai b8f91e6649 [fail] reset IsThisRendererActing correctly (#16042)
* [fail] reset IsThisRendererActing correctly

I missed this in https://github.com/facebook/react/pull/16039. I'd pointed at the wrong previous state, corrupting it in further use. This PR fixes that, and adds a test to make sure it doesn't happen again.

* warn for unacted effects only in strict mode
2019-07-03 03:04:22 +01:00
Sunil Pai bd846459d6 [fail] Only warn on unacted effects for strict / non sync modes (#16041)
* only warn on unacted effects for strict / non sync modes

(basically, when `fiber.mode !== 0b0000`)

Warnings on unacted effects may be too noisy, especially for legacy apps. This PR fires the warning only when in a non sync mode (concurrent/batched), or when in strict mode. This should make updating easier.

I also added batched mode tests to the act() suite.

* explicitly check for modes before warning, explicit tests for all modes
2019-07-03 01:29:45 +01:00
Dominic Gannaway 6b946ad9da [Flare] Add more functionality to Scroll event resonder (#16036) 2019-07-02 23:51:31 +01:00
Sunil Pai a457e02ae3 allow nested act()s from different renderers (#16039)
* allow nested `act()`s from different renderers

There are usecases where multiple renderers need to oprate inside an act() scope
- ReactDOM.render being used inside another component tree. The parent component will be rendered using ReactTestRenderer.create for a snapshot test or something.
- a ReactDOM instance interacting with a ReactTestRenderer instance (like for the new devtools)

This PR changes the way the acting sigils operate to allow for this. It keeps 2 booleans, one attached to React, one attached to the renderer. act() changes these values, and the workloop reads them to decide what warning to trigger.

I also renamed shouldWarnUnactedUpdates to warnsIfNotActing

* s/ReactIsActing/IsSomeRendererActing and s/ReactRendererIsActing/IsThisRendererActing
2019-07-02 22:20:17 +01:00
Anton Korzunov a865e4a642 Clone a custom hook node before use (#16019) 2019-07-02 17:54:10 +01:00
Dominic Gannaway 6cf2234a57 [Flare] Do not block mouse presses on scroll (#16033) 2019-07-02 16:58:46 +01:00
Sebastian Markbåge 5cb8f6f344 Add tail="collapsed" option to SuspenseList (#16007)
* Add tail="collapsed" option

* Fix issue with tail exceeding the CPU time limit

We used to assume that this didn't suspend but this branch happens in
both cases. This fixes it so that we first check if we suspended.

Now we can fix the tail so that it always render an additional fallback
in this scenario.
2019-07-01 19:56:34 -07:00
lunaruan 46bd11ac3e Flush sync bug (#16027)
* added flush sync test

* added code to run flushSync with ImmediatePriority

* added code to run flushSync with ImmediatePriority

* fixed flow error

* fixed flow error
2019-07-01 16:58:04 -07:00
Sebastian Markbåge 933c664ad6 SuspenseList Optimizations (#16005)
* Add a bunch of optimizations to SuspenseList

We now are able to bail out of reconciliation and splitting out the tail
during deep updates that hasn't changed the child props. This only
works while the list wasn't suspended before.

I also moved the second render of the "head" to the complete phase. This
cleans it up a bit for the tail collapsing PR.

For this second pass I also use a new technique of resetting the child
Fibers for the second pass. This is effectively a fast path to avoid
reconciling the children against props again.

* Move to didSuspend from SuspenseListState to the effectTag

The effectTag now tracks whether the previous commit was suspended.

This frees up SuspenseListState to be render-phase only state.

We use null to mean the default "independent" mode.

* Rename to SuspenseListState to SuspenseListRenderState

* Reuse SuspenseListRenderState across render passes

* Add optimization to bail out of scanning children if they can't be suspended

This optimized the deep update case or initial render without anything
suspending.

We have some information available to us that tell us if nothing has
suspended in the past and nothing has suspended this render pass.

This also fixes a bug where we didn't tag the previous render as having
suspended boundaries if we didn't need to force a rerender.

* rm printChildren

oops
2019-07-01 14:25:07 -07:00
Heaven fbbbea16e1 fix word async -> concurrent (#15844) 2019-07-01 17:32:29 +01:00
Dominic Gannaway eb2ace1281 [Flare] Bring Flare support to React Native Fabric (#15887) 2019-06-28 01:22:32 +01:00
Dominic Gannaway 9b0bd43550 [Flare] Re-label Flare flag (#16014) 2019-06-28 01:11:11 +01:00
Dominic Gannaway 8b88ac2592 [Flare] Remove event targets including TouchHitTarget (#16011) 2019-06-27 23:58:48 +01:00
Dan Abramov f11540926d Handle changes at module boundaries (#16002) 2019-06-27 20:53:03 +01:00
Benedikt Meurer 915dfe6977 Slightly improve performance of hydration. (#15998)
* Slightly improve performance of hydration.

Avoid loading nodeType and data couple times from the same node in a row,
but instead load them only once, which will help engines to run this code
faster, especially during startup of the application. The general approach
is still not ideal, since hydrating this way forces the browser engine
to materialize JavaScript wrapper objects for all DOM nodes, even if they
are not interesting to hydration itself.

* Fix condition for COMMENT_NODEs.

* Improve general code readability
2019-06-27 07:23:14 -07:00
Dominic Gannaway 824e9bec7a [Flare] Fix issues with touch + pointer interactions (#15997) 2019-06-26 22:25:49 +01:00
Dominic Gannaway dd93357aa0 [Flare] Move click handling back into target phase (#15993) 2019-06-26 20:44:44 +01:00
Andrew Clark 4d307de458 Prefix mock Scheduler APIs with _unstable (#15999)
For now this is only meant to be consumed via `act`.
2019-06-26 12:16:08 -07:00
Brandon Dail 9b55bcfc6b [Flare] Add Hooks to event modules (#15953) 2019-06-26 08:47:21 +01:00
Ricky 20da1dae4b Fix error logging in getDerivedStateFromProps (#15797)
* Fix error logging in getDerivedStateFromProps

* Update tests, don't log for both error boundary methods

* Re-add change lost in rebase
2019-06-25 18:02:27 +01:00
Dominic Gannaway 6088a201e1 [Flare] Fix Press scroll cancellation handling (#15983) 2019-06-25 14:31:48 +01:00
Dominic Gannaway fd601fb219 [Flare] Move all event responders to dom directory (#15981) 2019-06-25 09:32:20 +01:00
Veniamin Krol 827cbc4d00 Rename StatelessComponent to FunctionComponent in react-is/README.md (#15963) 2019-06-24 16:21:58 -07:00
Dan Abramov d48db594ec eslint-plugin-react-hooks@1.6.1 2019-06-24 22:31:14 +01:00
Thomas Broyer 7439b48cf4 Add explicit support for ESLint 6.0.0 (#15974)
Preemptively update tests wrt 'parser' requiring an absolute
path rather than a package name, even though the project is
still using ESLint 4.

Fixes #15971
2019-06-24 22:30:12 +01:00
Sunil Pai fce15f14d3 don't fire missing act() warnings for react-art (#15975)
* use toWarnDev for dom fixture tests

forks toWarnDev from root into fixture/dom, updates tes tests to use it

* disable act() warnings for react-art()

- For 'secondary' renderers like react-act, we don't want to fire missing act() warnings; the wrapping renderer will fire warnings anyway, and when it flushes, it flushes effects *across* renderers.

- I could have used isPrimaryRenderer as the flag, but this is marked as false for react-test-renderer, and we *do* want the warning to fire for it. Hence a new flag.

* add missing dependency `art` to fixtures/dom
2019-06-24 19:18:26 +01:00
Dominic Gannaway 20f3546963 [Flare] Ensure Press event hook does not execute side-effects (#15976) 2019-06-24 18:31:49 +01:00
Dan Abramov d420d2ccb6 [Fresh] Retry failed roots on refresh (#15966)
* Retry failed roots on refresh

* Don't prevent retry after error -> render(null) special case

The check wasn't very resilient because in Concurrent Mode it looks like we can get further follow-up commits even if we captured an error. So we can't reliably distinguish the case where after an error you _manually_ rendered null.

Retrying on an edit after a tree failed _and_ you rendered null in the same tree seems fine. It's also very unlikely a pattern like this actually exists in the wild.
2019-06-24 16:54:54 +01:00
Sunil Pai 04b77c6304 followup to #15763, fix failing test in ReactDOMTracing-test (#15972)
* followup to #15763, failing tests in ReactDOMTracing-test

It was me. I broke the build.

* [ignore] add a newline to trigger a build
2019-06-24 11:44:37 +01:00
Sunil Pai e1c5e8720d warn if passive effects get queued outside of an act() call. (#15763)
* warn if passive effects get queued outside of an act() call

While the code itself isn't much (it adds the warning to mountEffect() and updateEffect() in ReactFiberHooks), it does change a lot of our tests. We follow a bad-ish pattern here, which is doing asserts inside act() scopes, but it makes sense for *us* because we're testing intermediate states, and we're manually flush/yield what we need in these tests.

This commit has one last failing test. Working on it.

* pass lint

* pass failing test, fixes another

- a test was failing in ReactDOMServerIntegrationHooks while testing an effect; the behaviour of yields was different from browser and server when wrapped with act(). further, because of how we initialized modules, act() around renders wasn't working corrrectly. solved by passing in ReactTestUtils in initModules, and checking on the finally yielded values in the specific test.
- in ReactUpdates, while testing an infinite recursion detection, the test needed to be wrapped in an act(), which would have caused the recusrsion error to throw. solived by rethrowing the error from inside the act().

* pass ReactDOMServerSuspense

* stray todo

* a better message, consistent with the state update one.
2019-06-24 11:18:24 +01:00
Dan Abramov 39b97e8eb8 Report refreshed families to the caller (#15957) 2019-06-22 23:57:54 +01:00
Dan Abramov d271df5c99 Use function expression for custom Hook signature argument (#15956) 2019-06-22 11:54:22 +01:00
Andrew Clark 4189f712c1 [Scheduler] Increase max frame length to 300
Forgot to apply this change before merging.

https://github.com/facebook/react/pull/15959#discussion_r296429705
2019-06-22 01:38:19 -07:00
Andrew Clark 595c9414ba [Scheduler] Fix navigator.isInputPending call
Must be called as a method.
2019-06-22 00:50:13 -07:00
Andrew Clark e7fcfe1047 [scheduler] Put isPendingInput behind a flag (#15962) 2019-06-22 00:46:27 -07:00
Andrew Clark 6568a79931 [Scheduler] requestPaint (#15960)
* [Scheduler] requestPaint

Signals to Scheduler that the browser needs to paint the screen. React
will call it in the commit phase. Scheduler will yield at the end of
the current frame, even if there is no pending input.

When `isInputPending` is not available, this has no effect, because we
yield at the end of every frame regardless.

React will call `requestPaint` in the commit phase as long as there's at
least one effect. We could choose not to call it if none of the effects
are DOM mutations, but this is so rare that it doesn't seem worthwhile
to bother checking.

* Fall back gracefully if requestPaint is missing
2019-06-22 00:15:09 -07:00
Andrew Clark 8d4ddd33ac [Scheduler] Yield less if there's no pending input (#15959)
At the end of each frame, Scheduler yields control of the main thread so
the browser can execute important tasks; most importantly, painting the
screen and responding to user input. There's some overhead involved in
regaining control of the main thread, so we'd like to yield as
infrequently as possible to keep the UI responsive.

The reason we yield on every frame is because there's no way for us to
know whether we're blocking user input.

`isInputPending` is an experimental browser API that gives us this
information. It tells us whether there's a pending user input, which
also means it tells us if there's *not* a pending user input. We can use
this signal to decide whether it's OK not to yield.

There's a max frame length after which we'll yield regardless, as a
precaution against blocking non-input tasks that we don't know about.
2019-06-22 00:05:38 -07:00
Sebastian Markbåge d77d12510b Expire rendering the tail of SuspenseList after a timeout (#15946)
* Expire rendering the tail of SuspenseList after a timeout

This is the first Suspense feature that isn't actually dependent on IO.

The thinking here is that it's normal for a SuspenseList to show loading
states, and it'll be designed to handle it one at a time.

However, sometimes there are lists with really big items that take a long
time to CPU render. Since data can become available as we do that, it is
likely that we have all the data and become CPU bound.

In that case, the list would naively just render until the end and then
display all items at once. I think that's actually what you want for fast
lists. However, for slow ones (like News Feed), you're better off showing
a few rows at a time.

It's not necessarily one at a time because if you can do many in a short
period of time and fit them all on the screen, then it's better to do them
all at once than pop them in one at a time very quickly.

Therefore, I use a heuristic of trying to render as many rows as I can in
500ms before giving up.

This timer starts before the first row of the tail and we only check it
after. This ensures that we always make a little progress each attempt.
An alternative approach could be to start the time before doing the head
of the list but we don't want that being slow prevent us from making
further progress.

Currently, I disable this optimization at Never priority because there's
nothing intermediate that becomes visible anyway.

* Fix tracing through a SuspenseList

This ensures that we can spawn new work during render through arbitrary
priorities.

We'll need this for other features too.

Since each priority can commit separately we need to use an array to
include the current interactions on each priority.
2019-06-21 18:05:34 -07:00
Dominic Gannaway dc298fdf91 [Flare] Refinements to useEvent hook (#15955) 2019-06-21 23:10:55 +01:00
Dominic Gannaway 696609d49a [Fiber] Clear down dependencies during detachFiber (#15947) 2019-06-21 19:54:04 +01:00
Dominic Gannaway a5ed2f98f9 [Flare] Guard against stateNode being null (#15952) 2019-06-21 19:14:03 +01:00
Dominic Gannaway 34ce57ae75 [Flare] Refine flow type annotations (#15950) 2019-06-21 12:32:43 +01:00
Dominic Gannaway 4f92fbce5c [Flare] Move createEvent back to React object (#15943) 2019-06-21 10:12:56 +01:00
Andrew Clark 175111de72 Lazily initialize dependencies object (#15944)
Most fibers do not have events or context, so we save memory lazily
initializing this container node.

Follow-up from #15927
2019-06-20 20:12:22 -07:00
Dominic Gannaway 720db4cbe6 [Flare] Add useEvent hook implementation (#15927)
* [Flare] Add useEvent hook implementation

Validate hooks have decendent event components

Few fixes and displayName changes

Fix more responder bugs

Update error codes

* Add another test

* Address feedback
2019-06-20 19:12:40 -07:00
Nicolas Gallagher 6ff4c9de1c [Flare] Press: fix stale deactivation region state (#15931)
The responder region calculation logic wasn't updating the deactivation region
during the lifetime of an event instance, causing incorrect behaviour when the
current press ends outside the press target and if the press target has moved
since the last time the first-and-only time the deactivation region was
measured.
2019-06-20 17:10:54 -07:00
Dan Abramov 7a4c3e3b73 Make global names more obscure (#15941) 2019-06-20 20:20:09 +01:00
Sebastian Markbåge 270dc2e4de Add forwards and backwards options to SuspenseList (#15918)
* Add forwards option

* Add backwards option

* Add comment

* Add customized warning messages for case and typos

* Add some more tests for insertions and updates in start/middle/end
2019-06-20 11:03:47 -07:00