Commit Graph

4004 Commits

Author SHA1 Message Date
zhoulixiang 01e2bff1dc Remove unnecessary check (#24332) 2022-04-11 20:08:29 +01:00
dan d9a0f9e203 Delete create-subscription folder (#24288) 2022-04-11 20:07:22 +01:00
Andrew Clark f993ffc514 Fix infinite update loop that happens when an unmemoized value is passed to useDeferredValue (#24247)
* Fix infinite loop if unmemoized val passed to uDV

The current implementation of useDeferredValue will spawn a new
render any time the input value is different from the previous one. So
if you pass an unmemoized value (like an inline object), it will never
stop spawning new renders.

The fix is to only defer during an urgent render. If we're already
inside a transition, retry, offscreen, or other non-urgen render, then
we can use the latest value.

* Temporarily disable "long nested update" warning

DevTools' timeline profiler warns if an update inside a layout effect
results in an expensive re-render. However, it misattributes renders
that are spawned from a sync render at lower priority. This affects the
new implementation of useDeferredValue but it would also apply to things
like Offscreen.

It's not obvious to me how to fix this given how DevTools models the
idea of a "nested update" so I'm disabling the warning for now to
unblock the bugfix for useDeferredValue.
2022-04-11 12:34:03 -04:00
Josh Story fa58002262 [Fizz] Pipeable Stream Perf (#24291)
* Add fixture for comparing baseline render perf for renderToString and renderToPipeableStream

Modified from ssr2 and https://github.com/SuperOleg39/react-ssr-perf-test

* Implement buffering in pipeable streams

The previous implementation of pipeable streaming (Node) suffered some performance issues brought about by the high chunk counts and innefficiencies with how node streams handle this situation. In particular the use of cork/uncork was meant to alleviate this but these methods do not do anything unless the receiving Writable Stream implements _writev which many won't.

This change adopts the view based buffering techniques previously implemented for the Browser execution context. The main difference is the use of backpressure provided by the writable stream which is not implementable in the other context. Another change to note is the use of standards constructs like TextEncoder and TypedArrays.

* Implement encodeInto during flushCompletedQueues

encodeInto allows us to write directly to the view buffer that will end up getting streamed instead of encoding into an intermediate buffer and then copying that data.
2022-04-11 09:13:44 -07:00
Leo 0568c0f8cd Replace zero with NoLanes for consistency in FiberLane (#24327) 2022-04-09 20:29:08 +01:00
Luna Ruan e0160d50c5 add transition tracing transitions stack (#24321)
Added a transitions stack for to keep track of which transitions are still happening for the current boundary.
* On the root, we will get all transitions that have been initiated for the corresponding lanes.
* Whenever we encounter a suspended boundary, we will add all transitions on the stack onto the boundary
* Whenever we encounter a boundary that just unsuspended, we will add all transitions on the boundary onto the stack
A transition will be considered complete when there are no boundaries that have the associated transition
2022-04-08 17:48:30 -07:00
Luna Ruan b0f13e5d39 add pendingPassiveTransitions (#24320)
Add pendingPassiveTransitions work loop module level variable. Because workInProgressTransitions might change before we process it in the passive effects, we introduce a new variable, pendingPassiveTransitions, where we store the transitions until we can actually process them in the commit phase.
2022-04-08 16:35:18 -07:00
Luna Ruan 60e63b960f remove console.error in ReactFiberLane (#24319)
We changed the implementation of root.transitionLanes so that, if there is no transitions for a given lane, we use null instead of an array. This means that this error is no longer valid, so we are removing it
2022-04-08 15:33:52 -07:00
Andrew Clark ec52a5698e Fix: Don't call cWU if already unmounted
When a tree goes offscreen, we unmount all the effects just like we
would in a normal deletion. (Conceptually it _is_ a deletion; we keep
the fiber around so we can reuse its state if the tree mounts again.)

If an offscreen component gets deleted "for real", we shouldn't unmount
it again.

The fix is to track on the stack whether we're inside a hidden tree.

We already had a stack variable for this purpose, called
`offscreenSubtreeWasHidden`, in another part of the commit phase, so I
reused that variable instead of creating a new one. (The name is a bit
confusing: "was" refers to the current tree before this commit. So, the
"previous current".)

Co-authored-by: dan <dan.abramov@me.com>
2022-04-08 18:03:15 -04:00
Andrew Clark 46db4e996d Combine deletion phase into single recursive function
Similar to the previous step, this converts the deletion phase into
a single recursive function. Although there's less code, this one is
a bit trickier because it's already contains some stack-like logic
for tracking the nearest host parent. But instead of using the actual
stack, it repeatedly searches up the fiber return path to find the
nearest host parent.

Instead, I've changed it to track the nearest host parent on the
JS stack.

(We still search up the return path once, to set the initial host parent
right before entering a deleted tree. As a follow up, we can instead
push this to the stack as we traverse during the main mutation phase.)
2022-04-08 18:01:39 -04:00
Andrew Clark 481dece580 Use recursion to traverse during mutation phase
Most of the commit phase uses iterative loops to traverse the tree.
Originally we thought this would be faster than using recursion, but
a while back @trueadm did some performance testing and found that the
loop was slower because we assign to the `return` pointer before
entering a subtree (which we have to do because the `return` pointer
is not always consistent; it could point to one of two fibers).

The other motivation is so we can take advantage of the JS stack to
track contextual information, like the nearest host parent.

We already use recursion in a few places; this changes the mutation
phase to use it, too.
2022-04-08 18:01:21 -04:00
Andrew Clark f9e6aef828 Wrap try-catch directly around each user function
This moves the try-catch from around each fiber's mutation phase to
direclty around each user function (effect function, callback, etc).

We already do this when unmounting because if one unmount function
errors, we still need to call all the others so they can clean up
their resources.

Previously we didn't bother to do this for anything but unmount,
because if a mount effect throws, we're going to delete that whole
tree anyway.

But now that we're switching from an iterative loop to a recursive one,
we don't want every call frame on the stack to have a try-catch, since
the error handling requires additional memory.

Wrapping every user function is a bit tedious, but it's better
for performance. Many of them already had try blocks around
them already.
2022-04-08 18:00:42 -04:00
Andrew Clark bcc1b3121e Move reportUncaughtErrorInDev to captureCommitPhaseError
reportUncaughtErrorInDev is always followed by captureCommitPhaseError,
so we can move it into that function.
2022-04-08 18:00:33 -04:00
Andrew Clark c99c5f1df6 Move ad hoc flag checks into main switch statement
We should always refine the type of fiber before checking the effect
flag, because the fiber tag is more specific.

Now we have a single switch statement for all mutation effects.
2022-04-08 18:00:13 -04:00
Andrew Clark 54b5b32d53 Move Update flag check into each switch case
The fiber tag is more specific than the effect flag, so we should always
refine the type of work first, to minimize redundant checks.

In the next step I'll move all other other flag checks in this function
into the same switch statement.
2022-04-08 17:59:54 -04:00
Andrew Clark e66e7a0fb8 Inline commitWork into commitMutationOnFiber
There's not really any reason these should be separate functions. The
factoring has gotten sloppy and redundant because there's similar logic
in both places, which is more obvious now that they're combined.

Next I'll start combining the redundant branches.
2022-04-08 17:59:32 -04:00
Andrew Clark 12d7a9ad70 Combine commitWork into single switch statement
commitWork is forked into a separate implementation for mutation mode
(DOM) and persistent mode (React Native). But unlike when it was first
introduced, there's more overlap than differences between the forks,
mainly because we've added new types of fibers. So this joins the two
forks and adds more local branches where the behavior actually
diverges: host nodes, host containers, and portals.
2022-04-08 17:59:14 -04:00
Andrew Clark ea7b2ec289 Remove wrong return pointer warning
I'm about to refactor part of the commit phase to use recursion instead
of iteration. As part of that change, we will no longer assign the
`return` pointer when traversing into a subtree. So I'm disabling
the internal warning that fires if the return pointer is not consistent
with the parent during the commit phase.

I had originally added this warning to help prevent mistakes when
traversing the tree iteratively, but since we're intentionally switching
to recursion instead, we don't need it.
2022-04-08 17:58:52 -04:00
Ricky 8dcedba15a Add fallback shim for AbortController (#24285)
* Add fallback shim for AbortController

* Replace shim with a minimal stub

* replace-fork

* Better minification

* Fix flow

* Even smaller

* replace-fork

* Revert back to object constructor

* replace-fork
2022-04-08 15:53:40 -04:00
Ricky b86baa1cb7 Add back lost cache test (#24317) 2022-04-08 15:34:41 -04:00
Leo bafe912a5f update types for InputContinuousLane and DefaultLane (#24316) 2022-04-08 18:51:40 +01:00
Luna Ruan 4ebaeae40d moved mutation code to passive (#24251)
This PR moves the code for transition tracing in the mutation phase that adds transitions to the pending callbacks object (to be called sometime later after paint) from the mutation to the passive phase.

Things to think about:

Passive effects can be flushed before or after paint. How do we make sure that we get the correct end time for the interaction?
2022-04-08 09:28:20 -07:00
Brian Vaughn 5b2e7253f9 React DevTools 4.24.3 -> 4.24.4 (#24315) 2022-04-08 11:38:07 -04:00
Leo caa60e8fcc update types for NonIdleLanes and IdleLane (#24313) 2022-04-08 11:01:18 -04:00
Brian Vaughn 65f35035a6 Allow react-devtools-inline createStore() method to override Store config params (#24303) 2022-04-08 08:59:12 -04:00
Stephen Cyron 1f7a901d7b Fix false positive lint error with large number of branches (#24287)
* Switched RulesOfHooks.js to use BigInt. Added test and updated .eslintrc.js to use es2020.

* Added BigInt as readonly global in eslintrc.cjs.js and eslintrc.cjs2015.js

* Added comment to RulesOfHooks.js that gets rid of BigInt eslint error

* Got rid of changes in .eslintrc.js and yarn.lock

* Move global down

Co-authored-by: stephen cyron <stephen.cyron@fdmgroup.com>
Co-authored-by: dan <dan.abramov@gmail.com>
2022-04-08 00:22:47 +01:00
dan f56dfe950b Warn on setState() in useInsertionEffect() (#24298)
* Warn on setState() in useInsertionEffect()

* Use existing DEV reset mechanism
2022-04-07 20:12:49 +01:00
Sebastian Silbermann 548b542b41 Update renderToPipeableStream#options.onShellError to match usage (#24299) 2022-04-07 20:06:54 +01:00
dan d68b09defc Fix warning about setState in useEffect (#24295)
* Fix warning about setState in useEffect

* Fix test

* Fix multiple roots
2022-04-07 18:06:35 +01:00
dan 0579154772 Update create-subscription README (#24294) 2022-04-07 16:41:38 +01:00
dan e8f4a6653d Fix import in example 2022-04-07 14:12:58 +01:00
dan 3e8c91c5f8 Fix import in README 2022-04-07 13:46:36 +01:00
dan bb49abea23 Update some READMEs (#24290)
* Update some READMEs

* Update README.md
2022-04-07 02:35:01 +01:00
Sebastian Markbåge 4bc465a16f Rename Controls to PipeableStream (#24286)
This type isn't exported so it's technically not public.

This object mimics a ReadableStream.

Currently this is safe to destructure and call separately but I'm not sure
that's even guaranteed. It should probably be treated as a class in docs.
2022-04-06 19:27:38 -04:00
zhoulixiang ece5295e5a Remove unnecessary flag check (#24284) 2022-04-06 17:42:53 +01:00
alireza molaee 1d1fa94a66 Fix false positive warning about react-dom/client with UMD builds (#24274) 2022-04-05 02:56:18 +01:00
dan 9ededef945 Don't mute hydration errors forcing client render (#24276)
* Don't mute hydration errors forcing client render

* Nits
2022-04-05 02:11:22 +01:00
dan 5f7f528083 Add more tests for suppressHydrationWarning (#24275)
* More tests for suppressHydrationWarning

* Move suppressHydration tests to new file

* Extract more tests

* Test name

* Test legacy behavior too
2022-04-05 00:04:15 +01:00
dan fc47cb1b61 Fix suppressHydrationWarning not working in production (#24271) 2022-04-04 16:23:58 +01:00
Hikari Hayashi 985272e268 Fix name mismatch in react-reconciler custom build. (#24272) 2022-04-04 09:47:36 +01:00
Luna Ruan b8cfda15e1 changed Transitions type to Array<Transition> (#24249)
Changed the Transitions type to Array<Transition> because Transitions was confusing
2022-04-01 17:02:28 -04:00
Mengdi "Monday" Chen c89a15c716 [ReactDebugTools] wrap uncaught error from rendering user's component (#24216)
* [ReactDebugTools] wrap uncaught error from rendering user's component

* fix lint

* make error names more package specific

* update per review comments

* fix tests

* fix lint

* fix tests

* fix lint

* fix error name & nits

* try catch instead of mocking error

* fix test for older node.js version

* avoid false positive from try-catch in tests
2022-04-01 14:38:11 -04:00
dan ebd7ff65b6 Don't recreate the same fallback on the client if hydrating suspends (#24236)
* Delay showing fallback if hydrating suspends

* Fix up

* Include all non-urgent lanes

* Moar tests

* Add test for transitions
2022-04-01 02:49:54 +01:00
dan 4db3ff6c1a Test suite for hydration diff warnings (#24229)
* Test suite for hydration diff warnings

* Test both variants

* Add more edge cases
2022-03-31 17:35:51 +01:00
Brian Vaughn aa05e73150 Add 4.4.0 release to eslint rules CHANGELOG (#24234) 2022-03-31 10:43:08 -04:00
Sebastian Silbermann 7e3121e1cf Remove unstable_createMutableSource from experimental build (#24209) 2022-03-30 17:05:07 +01:00
Mengdi "Monday" Chen 0415b18a10 [ReactDebugTools] add custom error type for future new hooks (#24168)
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
2022-03-30 11:07:12 -04:00
Brian Vaughn 8b95ea2cba Inline DevTools test snapshots and cleaned up tests (#24199) 2022-03-30 11:02:51 -04:00
Mengdi "Monday" Chen adb8ebc927 React DevTools 4.24.2 -> 4.24.3 (#24198) 2022-03-29 14:44:32 -04:00
Andrew Clark 34aa5cfe0d Update local package.jsons for 18 2022-03-29 12:07:33 -04:00