Commit Graph
16329 Commits
Author SHA1 Message Date
sebmarkbage 30d76c90ea [Fiber] Avoid return value from commitBeforeMutationEffects (#31922)
This is behind an unusual flag (enableCreateEventHandleAPI) that doesn't
serve a special return value. I'll be collecting other flags from this
phase too.

We can just use the global flag and reset it before the next mutation
phase. Unlike focusedInstanceHandle this doesn't leak any memory in the
meantime.

DiffTrain build for [d8b903f49e](https://github.com/facebook/react/commit/d8b903f49edebdd9ed081ff0514c28fe130cd510)
2025-01-02 11:44:05 -08:00
sebmarkbage 4609a1dd06 [Fiber] Gate Update flag on BeforeMutationMask on flags (#31921)
We're currently visiting the snapshot phase for every `Update` flag even
though we rarely have to do anything in the Snapshot phase.

The only flags that seem to use these wider visits is
`enableCreateEventHandleAPI` and `enableUseEffectEventHook` but really
neither of those should do that neither. They should schedule explicit
Snapshot phases if needed.

DiffTrain build for [6ca7fbe884](https://github.com/facebook/react/commit/6ca7fbe884d17ef6c18d143421cc3e232bbba516)
2025-01-02 11:43:08 -08:00
sebmarkbageandRicky 4f7e527e91 [Fiber] Mark error boundaries and commit phases when an error is thrown (#31876)
This tracks commit phase errors and marks the component that errored as
red. These also get the errors attached to the entry.

<img width="1505" alt="Screenshot 2024-12-20 at 2 40 14 PM"
src="https://github.com/user-attachments/assets/cac3ead7-a024-4e33-ab27-2e95293c4299"
/>

In the render phase I just mark the Error Boundary that caught the
error. We don't have access to the actual error since it's locked behind
closures in the update queue. We could probably expose that someway.

<img width="949" alt="Screenshot 2024-12-20 at 1 49 05 PM"
src="https://github.com/user-attachments/assets/3032455d-d9f2-462b-9c07-7be23663ecd3"
/>

Follow ups:

Since the Error Boundary doesn't commit its attempted render, we don't
log those. If we did then maybe we should just mark the errored
component like I do for the commit phase. We could potentially walk the
list of errors and log the captured fibers and just log their entries as
children.

We could also potentially walk the uncommitted Fiber tree by stashing it
somewhere or even getting it from the alternate. This could be done on
Suspense boundaries too to track failed hydrations.

---------

Co-authored-by: Ricky <rickhanlonii@gmail.com>

DiffTrain build for [0de1233fd1](https://github.com/facebook/react/commit/0de1233fd180969f7ffdfc98151922f2466ceb1f)
2025-01-02 10:35:46 -08:00
sebmarkbage 4fe69bfced [Fiber] Mark cascading updates (#31866)
A common source of performance problems is due to cascading renders from
calling `setState` in `useLayoutEffect` or `useEffect`. This marks the
entry from the update to when we start the render as red and `"Cascade"`
to highlight this.

<img width="964" alt="Screenshot 2024-12-19 at 10 54 59 PM"
src="https://github.com/user-attachments/assets/2bfa91e6-1dc1-4b7f-a659-50aaf2a97e83"
/>

In addition to this case, there's another case where you call `setState`
multiple times in the same event causing multiple renders. This might be
due to multiple `flushSync`, or spawned a microtasks from a
`useLayoutEffect`. In theory it could also be from a microtask scheduled
after the first `setState`. This one we can only detect if it's from an
event that has a `window.event` since otherwise it's hard to know if
we're still in the same event.

<img width="1210" alt="Screenshot 2024-12-19 at 11 38 44 PM"
src="https://github.com/user-attachments/assets/ee188bc4-8ebb-4e95-b5a5-4d724856c27d"
/>

I decided against making a ping in a microtask considered a cascade.
Because that should ideally be using the Suspense Optimization and so
wouldn't be considered multi-pass.

<img width="1284" alt="Screenshot 2024-12-19 at 11 07 30 PM"
src="https://github.com/user-attachments/assets/2d173750-a475-41a0-b6cf-679d15c4ca97"
/>

We might consider making the whole render phase and maybe commit phase
red but that should maybe reserved for actual errors. The "Blocked"
phase really represents the `setState` and so will have the stack trace
of the first update.

DiffTrain build for [1e9eb95db5](https://github.com/facebook/react/commit/1e9eb95db5b3a2064ecc26915a4e640b3a9bdaf5)
2025-01-02 10:11:43 -08:00
sebmarkbage e34e27e76b [Fiber] Yield every other frame for Transition/Retry work (#31828)
This flag first moves the `shouldYield()` logic into React itself. We
need this for `postTask` compatibility anyway since this logic is no
longer a concern of the scheduler. This means that there can also be no
global `requestPaint()` that asks for painting earlier. So this is best
rolled out with `enableAlwaysYieldScheduler` (and ideally
`enableYieldingBeforePassive`) instead of `enableRequestPaint`.

Once in React we can change the yield timing heuristics. This uses the
previous 5ms for Idle work to keep everything responsive while doing
background work. However, for Transitions and Retries we have seen that
same thread animations (like loading states animating, or constant
animations like cool Three.js stuff) can take CPU time away from the
Transition that causes moving into new content to slow down. Therefore
we only yield every 25ms.

The purpose of this yield is not to avoid the overhead of yielding,
which is very low, but rather to intentionally block any frequently
occurring other main thread work like animations from starving our work.
If we could we could just tell everyone else to throttle their stuff for
ideal scheduling but that's not quite realistic. In other words, the
purpose of this is to reduce the frame rate of animations to 30 fps and
we achieve this by not yielding. We still do yield to allow the
animations to not just stall. This seems like a good balance.

The 5ms of Idle is because we don't really need to yield less often
since the overhead is low. We keep it low to allow 120 fps animations to
run if necessary and our work may not be the only work within a frame so
we need to yield early enough to leave enough time left.

Similarly we choose 25ms rather than say 35ms to ensure that we push
long enough to guarantee to half the frame rate but low enough that
there's plenty of time left for a rAF to power each animation every
other frame. It's also low enough that if something else interrupts the
work like a new interaction, we can still be responsive to that within
50ms or so. We also need to yield in case there's I/O work that needs to
get bounced through the main thread.

This flag is currently off everywhere since we have so many other
scheduling flags but that means there's some urgency to roll those out
fully so we can test this one. There's also some tests to update since
this doesn't go through the Mock scheduler anymore for yields.

DiffTrain build for [fe21c947c8](https://github.com/facebook/react/commit/fe21c947c82b173ae538aa1d215559ec3dccd103)
2025-01-02 10:09:41 -08:00
jackpope ee6423776d Turn off enableYieldingBeforePassive in internal test renderers (#31863)
https://github.com/facebook/react/pull/31785 turned on
`enableYieldingBeforePassive` for the internal test renderer builds. We
have some failing tests on the RN side blocking the sync so lets turn
these off for now.

DiffTrain build for [de82912e62](https://github.com/facebook/react/commit/de82912e620518d501680bbd93fbb5cc8d134223)
2024-12-20 06:56:17 -08:00
sebmarkbage e49ae8234d [Fiber] Mark hydrated components in tertiary color (green) (#31829)
This is a follow up to #31752.

This keeps track in the commit phase whether this subtree was hydrated.
If it was, then we mark those components in the Components track as
green. Just like the phase itself is marked as green.

If the boundary client rendered we instead mark it as "errored" and its
children given the plain primary render color (blue). I also collect the
hydration error for this case so we can include its message in the
details view. (Unfortunately this doesn't support newlines atm.)

Most of the time this happens in separate commits for each boundary but
it is possible to force a client render in the same pass as a hydration.
Such as if an update flows into a boundary that has been put into
fallback state after it was initially attempted.

<img width="1487" alt="Screenshot 2024-12-18 at 12 06 54 AM"
src="https://github.com/user-attachments/assets/74c57291-4d11-414c-9751-3dac3285a89a"
/>

DiffTrain build for [17520b6381](https://github.com/facebook/react/commit/17520b638190a20e745fe53299813b29b52dfc4c)
2024-12-18 21:01:05 -08:00
eps1lon 96ca300d2c Allow <script> and <template> tags in <select> tag (#31837)
DiffTrain build for [95465dc491](https://github.com/facebook/react/commit/95465dc4913377ab7e2fa98d956c87adb5e38e6c)
2024-12-18 12:36:25 -08:00
rickhanlonii ae1889e53e [tests] <StrictMode /> nested in tree is broken (#31825)
Adds a test that shows using <StrictMode /> anywhere outside of the root
node will not fire strict effects.

This works:

```js
root.render(
  <StrictMode>
    <App>
      <Children />
    </App>
  </StrictMode>
);
  ```

  This does not fire strict effects on mount:
```js
root.render(
  <App>
    <StrictMode>
      <Children />
    </StrictMode>
  </App>
);
```

DiffTrain build for [e1d843f4d8](https://github.com/facebook/react/commit/e1d843f4d8776bbf5d4fbd12a39bcfd2c565f900)
2024-12-18 10:37:25 -08:00
rickhanlonii 9c3a23ad90 [flags] Delete enableSchedulerDebugger (#31826)
The tool for this isn't used so I killed it internally and we can clean
up the code to make it easier to reduce the scheduler code.

DiffTrain build for [1e9ef39a87](https://github.com/facebook/react/commit/1e9ef39a8742889f8414c7df9c9e6ef463fe3d01)
2024-12-18 10:36:30 -08:00
eps1lonandeps1lon 010ea534a3 Ensure function arity is preserved after build (#31808)
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>

DiffTrain build for [2bd1c756c6](https://github.com/facebook/react/commit/2bd1c756c6fffefb00cdb2986218fa2701ece82e)
2024-12-18 05:16:18 -08:00
sebmarkbage 740cf068e9 [Fiber] Log Effect and Render Times in Offscreen Commit Phase (#31788)
In https://github.com/facebook/react/pull/30967 and
https://github.com/facebook/react/pull/30983 I added logging of the just
rendered components and the effects. However this didn't consider the
special Offscreen passes. So this adds the same thing to those passes.

Log component effect timings for disconnected/reconnected offscreen
subtrees. This includes initial mount of a Suspense boundary.

Log component render timings for reconnected and already offscreen
offscreen subtrees.

DiffTrain build for [6a4b46cd70](https://github.com/facebook/react/commit/6a4b46cd70d2672bc4be59dcb5b8dede22ed0cef)
2024-12-17 16:53:04 -08:00
sebmarkbage 990edd368f [Fiber] Schedule passive effects using the regular ensureRootIsScheduled flow (#31785)
This treats workInProgressRoot work and rootWithPendingPassiveEffects
the same way. Basically as long as there's some work on the root, yield
the current task. Including passive effects. This means that passive
effects are now a continuation instead of a separate callback. This can
mean they're earlier or later than before. Later for Idle in case
there's other non-React work. Earlier for same Default if there's other
Default priority work.

This makes sense since increasing priority of the passive effects beyond
Idle doesn't really make sense for an Idle render.

However, for any given render at same priority it's more important to
complete this work than start something new.

Since we special case continuations to always yield to the browser, this
has the same effect as #31784 without implementing `requestPaint`. At
least assuming nothing else calls `requestPaint`.

<img width="587" alt="Screenshot 2024-12-14 at 5 37 37 PM"
src="https://github.com/user-attachments/assets/8641b172-8842-4191-8bf0-50cbe263a30c"
/>

DiffTrain build for [facec3ee71](https://github.com/facebook/react/commit/facec3ee71fff8b23f1e91005fce730cc96e4021)
2024-12-17 14:09:00 -08:00
jackpope 5963da6f07 Clean up enableLazyContextPropagation (#31810)
This flag has shipped everywhere, let's clean it up.

DiffTrain build for [34ee3919c3](https://github.com/facebook/react/commit/34ee3919c39bc9b149462322713a9811db4b8498)
2024-12-17 09:04:00 -08:00
rickhanlonii 95043fef8b [flags] Clean up scheduler flags (#31814)
These flags are hardcoded now, we can make them static.

DiffTrain build for [d428725882](https://github.com/facebook/react/commit/d42872588282b9eef56b8fa02441b33d596fd197)
2024-12-17 07:35:20 -08:00
rickhanlonii f08e9d394b Enable debugRenderPhaseSideEffectsForStrictMode in test renderers (#31761)
This flag controls the strict mode double invoke render/lifecycles/etc
behavior in Strict Mode.

The only place this flag is off is the test renderers, which it should
be on for.

If we can land this, we can follow up to remove the flag.

DiffTrain build for [975cea2d3d](https://github.com/facebook/react/commit/975cea2d3ddb95ad31f10ae112bdde5101725c85)
2024-12-16 19:59:27 -08:00
rickhanlonii 43a50eb8a3 Enable disableDefaultPropsExceptForClasses (#31804)
TODO: test this PR to see what internal tests fail

DiffTrain build for [49b1a956a9](https://github.com/facebook/react/commit/49b1a956a915da972e60221e9610d383fac08bd7)
2024-12-16 19:58:19 -08:00
rickhanlonii 2fceb0bacf Turn on useModernStrictMode in test renderers (#31769)
It's on everywhere else, let's turn this on so we can remove it.

Probably should have been turned on in the test renderer for 19.

DiffTrain build for [8dab5920e0](https://github.com/facebook/react/commit/8dab5920e019950874bcc9061480dd78c849e1d7)
2024-12-16 19:51:33 -08:00
jackpope cd62d054b5 Clean up context access profiling experiment (#31806)
We introduced the `unstable_useContextWithBailout` API to run compiler
based experiments. This API was designed to be an experiment proxy for
alternative approaches which would be heavier to implement. The
experiment turned out to be inconclusive. Since most of our performance
critical usage is already optimized, we weren't able to find a clear win
with this approach.

Since we don't have further plans for this API, let's clean it up.

DiffTrain build for [909ed63e0a](https://github.com/facebook/react/commit/909ed63e0adc162a95a4704d3ed07a956dcf9cd1)
2024-12-16 09:40:02 -08:00
rickhanlonii 517de859fc Flag for requestPaint (#31805)
Will run a quick experiment for this.

DiffTrain build for [f7b1273da2](https://github.com/facebook/react/commit/f7b1273da2c96057d3908f52f8587379d4418f66)
2024-12-16 08:26:02 -08:00
rickhanlonii fac54e0731 [flags] Cleanup enableCache (#31778)
This is landed everywhere

DiffTrain build for [e06c72fcf4](https://github.com/facebook/react/commit/e06c72fcf4632ad3117add713a25f6354631f037)
2024-12-15 09:41:35 -08:00
rickhanlonii 7be331e2ae [flags] Delete enableDebugTracing (#31780)
This is unused, even in the one builds that uses it, and we don't plan
on landing it in this form.

DiffTrain build for [2d320563f3](https://github.com/facebook/react/commit/2d320563f35ad75419983f166431055b4e7ed9f6)
2024-12-15 09:23:15 -08:00
sebmarkbage da9bea2acb Implement requestPaint in the actual scheduler (#31784)
When implementing passive effects we did a pretty massive oversight.
While the passive effect is scheduled into its own scheduler task, the
scheduler doesn't always yield to the browser if it has time left. That
means that if you have a fast commit phase, it might try to squeeze in
the passive effects in the same frame but those then might end being
very heavy.

We had `requestPaint()` for this but that was only implemented for the
`isInputPending` experiment. It wasn't thought we needed it for the
regular scheduler because it yields "every frame" anyway - but it
doesn't yield every task. While the `isInputPending` experiment showed
that it wasn't actually any significant impact, and it was better to
keep shorter yield time anyway. Which is why we deleted the code.
Whatever small win it did see in some cases might have been actually due
to this issue rather than anything to do with `isInputPending` at all.

As you can see in https://github.com/facebook/react/pull/31782 we do
have this implemented in the mock scheduler and a lot of behavior that
we assert assumes that this works.

So this just implements yielding after `requestPaint` is called.

Before:

<img width="1023" alt="Screenshot 2024-12-14 at 3 40 24 PM"
src="https://github.com/user-attachments/assets/d60f4bb2-c8f8-4f91-a402-9ac25b278450"
/>

After:

<img width="1108" alt="Screenshot 2024-12-14 at 3 41 25 PM"
src="https://github.com/user-attachments/assets/170cdb90-a049-436f-9501-be3fb9bc04ca"
/>

Notice how in after the native task is split into two. It might not
always actually paint and the native scheduler might make the same
mistake and think it has enough time left but it's at least less likely
to.

We do have another way to do this. When we yield a continuation we also
yield to the native browser. This is to enable the Suspense Optimization
(currently disabled) to work. We could do the same for passive effects
and, in fact, I have a branch that does but because that requires a lot
more tests to be fixed it's a lot more invasive of a change. The nice
thing about this approach is that this is not even running in tests at
all and the tests we do have assert that this is the behavior already. 😬

DiffTrain build for [c80b336d23](https://github.com/facebook/react/commit/c80b336d23aa472b5e5910268138ac0447d6ae19)
2024-12-14 13:24:44 -08:00
sebmarkbage 82c0c104e7 [Fiber] Schedule client renders using non-hydration lane (#31776)
Related to #31752.

When hydrating, we have two different ways of handling a Suspense
boundary that the server has already given up on and decided to client
render. If we have already hydrated the parent and then later this
happens, then we'll use the retry lane like any ping. If we discover
that it was already in client-render mode when we discover the Suspense
boundary for the first time, then schedule a default lane to let us
first finish the current render and then upgrade the priority to sync to
try to client render this boundary as soon as possible since we're
holding back content.

We used to use the `DefaultHydrationLane` for this but this is not
really a Hydration. It's actually a client render. If we get any other
updates flowing in from above at the same time we might as well do them
in the same pass instead of two passes. So this should be considered
more like any update.

This also means that visually the client render pass now gets painted as
a render instead of a hydration.

This show the flow of a shell being hydrated at the default priority,
then a Suspense boundary being discovered and hydrated at Idle and then
an inner boundary being discovered as client rendered which gets
upgraded to default.

<img width="1363" alt="Screenshot 2024-12-14 at 12 13 57 AM"
src="https://github.com/user-attachments/assets/a141133e-4856-4f38-a11f-f26bd00b6245"
/>

DiffTrain build for [d1dd7feabc](https://github.com/facebook/react/commit/d1dd7feabc63bf8ca61e9b3f4d78245a29ebbe9a)
2024-12-14 10:53:55 -08:00
sebmarkbage 2556bc0c6f Fix commong typo in <title> multiple children error message (#31777)
DiffTrain build for [0d67cc0651](https://github.com/facebook/react/commit/0d67cc065157b2b98843cd1e2578b0969765c54b)
2024-12-14 09:39:54 -08:00
rickhanlonii f161343f9b [flags] Cleanup enableUseMemoCacheHook (#31767)
Based off https://github.com/facebook/react/pull/31766

This has already landed everywhere.

DiffTrain build for [2e25ee373d](https://github.com/facebook/react/commit/2e25ee373d96a882cee9a1ee3d7fee3f498bde2d)
2024-12-14 08:18:28 -08:00
rickhanlonii e67f32fc5a Remove enableFilterEmptyStringAttributesDOM (#31765)
Base off https://github.com/facebook/react/pull/31764

This has landed everywhere

DiffTrain build for [4996a8fa5c](https://github.com/facebook/react/commit/4996a8fa5c5bf9e12e750c46b48f25656fb050cf)
2024-12-13 13:37:40 -08:00
rickhanlonii 1b27d1e4ad Remove enableComponentStackLocations (#31764)
This has landed everywhere

DiffTrain build for [3ad17ecd31](https://github.com/facebook/react/commit/3ad17ecd313a8e53b339adf8052e35b3d73f8c62)
2024-12-13 13:00:30 -08:00
rickhanlonii aa9b74aa4f Remove enableAsyncActions (#31757)
Based on https://github.com/facebook/react/pull/31756

This is landed everywhere

DiffTrain build for [ef63718a27](https://github.com/facebook/react/commit/ef63718a27407b6d6b262d6be92e6bf0a87ff1a3)
2024-12-13 11:05:30 -08:00
rickhanlonii 9f5fb91030 Remove disableIEWorkarounds (#31756)
Based off https://github.com/facebook/react/pull/31755

This is landed everywhere.

DiffTrain build for [fb12845d77](https://github.com/facebook/react/commit/fb12845d779667b35cc7f44eee6bea47f4db72ba)
2024-12-13 09:33:56 -08:00
jackpope 5b45911189 Fix useResourceEffect in Fizz (#31758)
We're seeing errors when testing useResourceEffect in SSR and it turns
out we're missing the noop dispatcher function on Fizz.

I tested a local build with this change and it resolved the late
mutation errors in the e2e tests.

DiffTrain build for [17ca4b157f](https://github.com/facebook/react/commit/17ca4b157fcba6c734583513353ba72376a7ba2d)
2024-12-13 08:33:45 -08:00
rickhanlonii f0381ca1dc Remove consoleManagedByDevToolsDuringStrictMode (#31755)
This is enabled everywhere except the test renderers, which don't use
it.

DiffTrain build for [4dff0e62b2](https://github.com/facebook/react/commit/4dff0e62b2320d8c97746a16c95efd9c9ad0bc07)
2024-12-13 08:13:39 -08:00
sebmarkbage 2a2d2f8273 [Fiber] Use hydration lanes when scheduling hydration work (#31751)
When scheduling the initial root and when using
`unstable_scheduleHydration` we should use the Hydration Lanes rather
than the raw update lane. This ensures that we're always hydrating using
a Hydration Lane or the Offscreen Lane rather than other lanes getting
some random hydration in it.

This fixes an issue where updating a root while it is still hydrating
causes it to trigger client rendering when it could just hydrate and
then apply the update on top of that.

It also fixes a potential performance issue where
`unstable_scheduleHydration` gets batched with an update that then ends
up forcing an update of a boundary that requires it to rewind to do the
hydration lane anyway. Might as well just start with the hydration
without the update applied first.

I added a kill switch (`enableHydrationLaneScheduling`) just in case but
seems very safe given that using `unstable_scheduleHydration` at all is
very rare and updating the root before the shell hydrates is extremely
rare (and used to trigger a recoverable error).

DiffTrain build for [d5e8f79cf4](https://github.com/facebook/react/commit/d5e8f79cf4d11fa7eee263b3f937deecbe65ffd7)
2024-12-12 20:13:02 -08:00
noahlemenandRick Hanlon 0bcbbf0082 Make enableOwnerStacks dynamic (#31661)
following up on https://github.com/facebook/react/pull/31287, fixing
tests

---------

Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>

DiffTrain build for [a4964987dc](https://github.com/facebook/react/commit/a4964987dc140526702e996223fe7ee293def8ac)
2024-12-11 09:07:47 -08:00
eps1lon 4e4144e71c react-hooks/rules-of-hooks: Improve support for do/while loops (#31720)
DiffTrain build for [7c4a7c9ddf](https://github.com/facebook/react/commit/7c4a7c9ddf2f1c8e223565af1256ea201ec0f303)
2024-12-10 13:53:31 -08:00
sebmarkbage 0558177043 Clean up findFiberByHostInstance from DevTools Hook (#31711)
The need for this was removed in
https://github.com/facebook/react/pull/30831

Since the new DevTools version has been released for a while and we
expect people to more or less auto-update. Future versions of React
don't need this.

Once we remove the remaining uses of `getInstanceFromNode` e.g. in the
deprecated internal `findDOMNode`/`findNodeHandle` and the event system,
we can completely remove the tagging of DOM nodes.

DiffTrain build for [3b597c0576](https://github.com/facebook/react/commit/3b597c0576977773910c77e075cc6d6308decb04)
2024-12-10 08:41:30 -08:00
gnoff e3aab58ef9 Register Suspense retry handlers in commit phase (#31667)
To avoid GC pressure and accidentally hanging onto old trees Suspense
boundary retries are now implemented in the commit phase. I used the
Callback flag which was previously only used to schedule callbacks for
Class components. This isn't quite semantically equivalent but it's
unused and seemingly compatible.

DiffTrain build for [de68d2f4a2](https://github.com/facebook/react/commit/de68d2f4a2403ad1ef46a3036ddc1f9080640588)
2024-12-04 08:09:37 -08:00
gnoff 8834a5b4ae Client render dehydrated Suspense boundaries on document load (#31620)
When streaming SSR while hydrating React will wait for Suspense
boundaries to be revealed by the SSR stream before attempting to hydrate
them. The rationale here is that the Server render is likely further
ahead of whatever the client would produce so waiting to let the server
stream in the UI is preferable to retrying on the client and possibly
delaying how quickly the primary content becomes available. However If
the connection closes early (user hits stop for instance) or there is a
server error which prevents additional HTML from being delivered to the
client this can put React into a broken state where the boundary never
resolves nor errors and the hydration never retries that boundary
freezing it in it's fallback state.

Once the document has fully loaded we know there is not way any
additional Suspense boundaries can arrive. This update changes react-dom
on the client to schedule client renders for any unfinished Suspense
boundaries upon document loading.

The technique for client rendering a fallback is pretty straight
forward. When hydrating a Suspense boundary if the Document is in
'complete' readyState we interpret pending boundaries as fallback
boundaries. If the readyState is not 'complete' we register an event to
retry the boundary when the DOMContentLoaded event fires.

To test this I needed JSDOM to model readyState. We previously had a
temporary implementation of readyState for SSR streaming but I ended up
implementing this as a mock of JSDOM that implements a fake readyState
that is mutable. It starts off in 'loading' readyState and you can
advance it by mutating document.readyState. You can also reset it to
'loading'. It fires events when changing states.

This seems like the least invasive way to get closer-to-real-browser
behavior in a way that won't require remembering this subtle detail
every time you create a test that asserts Suspense resolution order.

DiffTrain build for [16d2bbbd1f](https://github.com/facebook/react/commit/16d2bbbd1f1617d636ea0fd271b902a12a763c27)
2024-12-03 13:20:46 -08:00
poteto 61d48e4526 [crud] Only export uRC when flag is enabled (#31617)
It's tricky to do feature detection of uRC currently because it's always
present on the export. Let's conditionally export it instead.

DiffTrain build for [e3b7ef32be](https://github.com/facebook/react/commit/e3b7ef32be6a6d01ea050a10a218538e3a75c64f)
2024-11-22 13:24:25 -08:00
poteto 4005e3211d [crud] Fix deps comparison bug (#31599)
Fixes a bug with the experimental `useResourceEffect` hook where we
would compare the wrong deps when there happened to be another kind of
effect preceding the ResourceEffect. To do this correctly we need to add
a pointer to the ResourceEffect's identity on the update.

I also unified the previously separate push effect impls for resource
effects since they are always pushed together as a unit.

DiffTrain build for [c11c9510fa](https://github.com/facebook/react/commit/c11c9510fa14bbd87053685c19bfdfec2f427f49)
2024-11-20 14:02:01 -08:00
poteto 63038b40e0 [crud] Fix copy paste typo (#31588)
Happens to the best of us.

DiffTrain build for [7558ffe84d](https://github.com/facebook/react/commit/7558ffe84df6bab5d701fd90de1c6313f9a1c066)
2024-11-19 14:21:01 -08:00
eps1lon c506d49c28 fix[eslint-plugin-react-hooks]: Fix error when callback argument is an identifier with an as expression (#31119)
DiffTrain build for [eaf2d5c670](https://github.com/facebook/react/commit/eaf2d5c670c84124618977156d81946435922eb3)
2024-11-19 01:43:30 -08:00
poteto 3a9e9ff993 [crud] Basic implementation (#31523)
This PR introduces a new experimental hook `useResourceEffect`, which is
something that we're doing some very early initial tests on.

This may likely not pan out and will be removed or modified if so.
Please do not rely on it as it will break.

DiffTrain build for [047d95e85f](https://github.com/facebook/react/commit/047d95e85f0f0cfa6085b2e355e052a3c34ae24d)
2024-11-18 07:24:14 -08:00
sebmarkbage 215cf146f8 Track separate SuspendedOnAction flag by rethrowing a separate SuspenseActionException sentinel (#31554)
This lets us track separately if something was suspended on an Action
using useActionState rather than suspended on Data.

This approach feels quite bloated and it seems like we'd eventually
might want to read more information about the Promise that suspended and
the context it suspended in. As a more general reason for suspending.

The way useActionState works in combination with the prewarming is quite
unfortunate because 1) it renders blocking to update the isPending flag
whether you use it or not 2) it prewarms and suspends the useActionState
3) then it does another third render to get back into the useActionState
position again.

DiffTrain build for [92c0f5f85f](https://github.com/facebook/react/commit/92c0f5f85fed42024b17bf6595291f9f5d6e8734)
2024-11-15 15:00:42 -08:00
poteto 6aab9387b9 [crud] Rename Effect type (#31557)
Adds a new `Effect` type which for now just points to the `SimpleEffect`
type, in prepartion for later in the stack where we add more.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31557).
* #31523
* __->__ #31557
* #31556
* #31555

DiffTrain build for [053b3cb050](https://github.com/facebook/react/commit/053b3cb0503e26da6d1dfa02b74fa52e30936bd6)
2024-11-15 14:58:52 -08:00
sebmarkbage 06cc3b97bc Log Render Phases that Never Committed (#31548)
This includes:

- `Interrupted Render`: Interrupted Renders (setState or ping at higher
priority)
- `Prewarm`: Suspended Renders outside a Suspense boundary
(RootSuspendedWithDelay/RootSuspendedAtTheShell)
- `Errored Render`: Render that errored somewhere in the tree (Fatal or
Not) (which may or may not be retried and then complete)
- `Teared Render`: Due to useSyncExternalStore not matching (which will
do another sync attempt)

Suspended Commit:

<img width="893" alt="Screenshot 2024-11-14 at 11 47 40 PM"
src="https://github.com/user-attachments/assets/b25a6a8b-a5e9-4d66-b325-57aef4bf9dad">

Errored with a second recovery attempt that also errors:

<img width="976" alt="Screenshot 2024-11-15 at 12 09 06 AM"
src="https://github.com/user-attachments/assets/9ce52cbb-b587-4f1e-8b67-e51d9073ae5b">

DiffTrain build for [3720870a97](https://github.com/facebook/react/commit/3720870a979b48a1ea8776f64a190878b8558f2b)
2024-11-15 09:21:10 -08:00
sebmarkbage fcb79ce20b Unify RootDidNotComplete and RootSuspendedWithDelay exit path (#31547)
Also rename RootDidNotComplete to RootSuspendedAtTheShell since it
specifically means something suspended in the shell during hydration.

DiffTrain build for [8a41d6ceab](https://github.com/facebook/react/commit/8a41d6ceab8af642d8ab9ed04fc744a699f4ac09)
2024-11-14 20:58:53 -08:00
gnoff 9167300ff0 (chore): copy fix in <style> precedence error (#31524)
## Summary

This fixes a typo in the error that gets reported when Float errors
while hoisting a style tag that does not contain both `precedence` and
`href`. There was a typo in _conflict_ and the last part of the sentence
doesn't make sense. I assume it wasn't needed since the message already
suggests moving the style tag to the head manually.

DiffTrain build for [63cde684f5](https://github.com/facebook/react/commit/63cde684f5340b1ca73f6244501aac1c3d2c92a8)
2024-11-14 14:11:25 -08:00
sebmarkbage ed85198c3b Fix Overlapping "message" Bug in Performance Track (#31528)
When you schedule a microtask from render or effect and then call
setState (or ping) from there, the "event" is the event that React
scheduled (which will be a postMessage). The event time of this new
render will be before the last render finished.

We usually clamp these but in this scenario the update doesn't happen
while a render is happening. Causing overlapping events.

Before:

<img width="1229" alt="Screenshot 2024-11-12 at 11 01 30 PM"
src="https://github.com/user-attachments/assets/9652cf3b-b358-453c-b295-1239cbb15952">

Therefore when we finalize a render we need to store the end of the last
render so when we a new update comes in later with an event time earlier
than that, we know to clamp it.

There's also a special case here where when we enter the
`RootDidNotComplete` or `RootSuspendedWithDelay` case we neither leave
the root as in progress nor commit it. Those needs to finalize too.
Really this should be modeled as a suspended track that we haven't added
yet. That's the gap between "Blocked" and "message" below.

After:

<img width="1471" alt="Screenshot 2024-11-13 at 12 31 34 AM"
src="https://github.com/user-attachments/assets/b24f994e-9055-4b10-ad29-ad9b36302ffc">

I also fixed an issue where we may log the same event name multiple
times if we're rendering more than once in the same event. In this case
I just leave a blank trace between the last commit and the next update.

I also adding ignoring of the "message" event at all in these cases when
the event is from React's scheduling itself.

DiffTrain build for [c13986da78](https://github.com/facebook/react/commit/c13986da7866a1a70a73b7ee05c87a9618ce6d03)
2024-11-14 13:42:53 -08:00
acdlite e7777dc2cd Turn on enableSiblingPrerendering in canary (#31541)
In preparation for the next RC, I set this feature flag to true
everywhere. I did not delete the feature flag yet, in case there are yet
more bugs to be discovered.

I also didn't remove the dynamic feature flag from the Meta builds; I'll
let the Meta folks handle that.

DiffTrain build for [988e217670](https://github.com/facebook/react/commit/988e2176702fca9b25113d9a8a3e7e3f484e16f2)
2024-11-14 08:55:26 -08:00