Commit Graph

1168 Commits

Author SHA1 Message Date
sebmarkbage ea06e7b55a Make RefStatic and LayoutStatic the same bit (#31965)
Refs are basically just fancy Layout Effects. These are conceptually the
same thing and are always visited together so they don't need to be
different flags.

Whenever we disappear/reappear Offscreen content we need to do both Refs
and Layout Effects.

This is just indicating which phase needs to be visited and these are
always the same phase.

DiffTrain build for [3b009b4cd5](https://github.com/facebook/react/commit/3b009b4cd58d382cfde2a72232c87df1a34d56d5)
2025-01-02 18:30:47 -08:00
sebmarkbage 9619b0daab [Fiber] Refactor Commit Phase into Separate Functions for Before Mutation/Mutation/Layout (#31930)
This is doing some general clean up to be able to split the commit root three phases into three separate async steps.

DiffTrain build for [c81312e3a7](https://github.com/facebook/react/commit/c81312e3a78dcbf71ed98c8893abe6dbfeaef3f2)
2025-01-02 12:02:37 -08:00
sebmarkbage 32a72c9e43 [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:02 -08:00
sebmarkbage 80269ba62e [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:06 -08:00
sebmarkbage b675a57ad5 [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:45 -08:00
sebmarkbage c52345de2e [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 dce2833bf0 [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:44 -08:00
jackpope 8533013a0f 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:21 -08:00
jackpope 663e50c218 Fork Scheduler feature flags for native-fb (#31859)
#31787 introduces an experimental scheduler flag:
`enableAlwaysYieldScheduler`, which is turned off for www. There wasn't
a SchedulerFeatureFlags fork for native-fb, so the experimental change
was enabled in the Scheduler-dev build there which causes test failures
and is blocking the sync.

#31805 introduces another scheduler flag `enableRequestPaint`, which is
set as a `__VARIANT__` on www. I've set this to `true` here to preserve
the existing behavior. We can follow up with dynamic flags for native-fb
after unblocking the sync.

DiffTrain build for [bd76ce54d9](https://github.com/facebook/react/commit/bd76ce54d93153cc84d861bd59e906bc28e1c160)
2024-12-19 09:01:14 -08:00
rickhanlonii 49240b5444 [assert helpers] forwardRef-test (#31843)
Starting to convert the rest of tests to the `assertConsoleTypeDev`
helpers.

DiffTrain build for [8f92ea467e](https://github.com/facebook/react/commit/8f92ea467e2672a436e3e032299d5230d03187ed)
2024-12-19 09:00:00 -08:00
acdlite be7350cb9e Update runtime workflow to use HEAD commit (#31850)
This updates the CI workflow for the runtime build and tests to use the
HEAD commit of the PR branch rather than the Fake News merge commit that
the `@actions/checkout` action bafflingly defaults to.

Testing against the merge commit never made sense to me as a behavior
because as soon as someone updates upstream, it's out of date anyway.

It should just match the exact commit that the developer pushed, and the
once that appears in the GitHub UI.

DiffTrain build for [9463d51e51](https://github.com/facebook/react/commit/9463d51e515544bb3119dd4cec46ce2177cf4c62)
2024-12-19 07:25:31 -08:00
sebmarkbage 8b2a4d3ca5 [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
poteto 4db47b19da [ci] Don't cancel runs if more than one branch triggers CI (#31848)
This might primarily only affect those using Sapling for React
development, but pushing the same commit to multiple branches shouldn't
cancel the run

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

DiffTrain build for [7de040ccfa](https://github.com/facebook/react/commit/7de040ccfa49f4128f0f5c6a7a81c019b4a381b8)
2024-12-18 17:19:17 -08:00
poteto 5749e811a3 [ci] Validate downloaded build artifact (#31847)
Adds validation to download-build-artifacts to confirm that the
downloaded artifact matches what was requested.

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

DiffTrain build for [74e39ce2a1](https://github.com/facebook/react/commit/74e39ce2a1eec803936db8a29349f6fda176cce7)
2024-12-18 17:17:44 -08:00
rickhanlonii 8a8454eb6a [flags] Remove debugRenderPhaseSideEffectsForStrictMode (#31839)
This is enabled everywhere, we can just use the inline `__DEV__` checks.

DiffTrain build for [faf6c4dfdc](https://github.com/facebook/react/commit/faf6c4dfdcd3c9b3862af6a3afcb3d80abd407c0)
2024-12-18 14:58:23 -08:00
gnoff 428831b272 [Flight Reply] Reject any new Chunks not yet discovered at the time of reportGlobalError (#31840)
We might have already resolved models that are not pending and so are
not rejected by aborting the stream. When those later get parsed they
might discover new chunks which end up as pending. These should be
errored since they will never be able to resolve later.

This avoids infinitely hanging the stream.

This same fix needs to be ported to ReactFlightClient that has the same
issue.

DiffTrain build for [ef979d4703](https://github.com/facebook/react/commit/ef979d4703ffcd1f379a4b76195816bea3da3c81)
2024-12-18 13:04:03 -08:00
eps1lon f2bb2d4033 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:21 -08:00
rickhanlonii 227433ea29 [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:27 -08:00
rickhanlonii 82d7548ca8 [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:31 -08:00
eps1lon 7ab9a5406c 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:13 -08:00
sebmarkbage b34b7cf9b3 [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 332eb426a6 [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:08:59 -08:00
sebmarkbage e2c05f6d3f [Scheduler] Always yield to native macro tasks when a virtual task completes (#31787)
As an alternative to #31784.

We should really just always yield each virtual task to a native task.
So that it's 1:1 with native tasks. This affects when microtasks within
each task happens. This brings us closer to native `postTask` semantics
which makes it more seamless to just use that when available.

This still doesn't yield when a task expires to protect against
starvation.

DiffTrain build for [f5077bcc92](https://github.com/facebook/react/commit/f5077bcc925aa6d0ba2ca4041c875d35e24f6266)
2024-12-17 13:56:26 -08:00
jackpope 613f8c3daa 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:03:54 -08:00
rickhanlonii b8f981a626 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:31 -08:00
jackpope ec257f2233 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 b2af848838 [flags] Cleanup enableCache (#31778)
This is landed everywhere

DiffTrain build for [e06c72fcf4](https://github.com/facebook/react/commit/e06c72fcf4632ad3117add713a25f6354631f037)
2024-12-15 09:41:34 -08:00
rickhanlonii ddf7c2d9e3 [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:19 -08:00
sebmarkbage fec0ab6de4 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:42 -08:00
sebmarkbage 1122f7a5ae [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:54 -08:00
rickhanlonii eccdc2d892 [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:25 -08:00
rickhanlonii ed6385045c 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:38 -08:00
rickhanlonii b80e29561a Remove enableComponentStackLocations (#31764)
This has landed everywhere

DiffTrain build for [3ad17ecd31](https://github.com/facebook/react/commit/3ad17ecd313a8e53b339adf8052e35b3d73f8c62)
2024-12-13 13:00:29 -08:00
rickhanlonii 34f8925edb 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:33 -08:00
rickhanlonii 4d3cdac1a5 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:34:00 -08:00
rickhanlonii d5aa92eb85 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 40363dbca7 [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:05 -08:00
noahlemen 95e5f9519e 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:50 -08:00
hoxyq a7b82f010e Remove comment syntax from ReactNativeTypes (#31457)
# Summary

I'm working to get the main `react-native` package parsable by modern
Flow tooling (both `flow-bundler`, `flow-api-translator`).

This diff trivially removes some redundant Flow comment syntax in
`ReactNativeTypes.js`, which fixes parsing under these newer tools.

## How did you test this change?

Files were pasted into `react-native-github` under fbsource, where Flow
validates .

DiffTrain build for [92b62f500c](https://github.com/facebook/react/commit/92b62f500c3fca44a9dc9ead936ef3bf19481f02)
2024-12-11 09:02:35 -08:00
sebmarkbage 2564c8f567 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:33 -08:00
gnoff a3b43879ac 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:35 -08:00
gnoff 73566a7a67 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:44 -08:00
poteto 2241a5a1c8 [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:23:36 -08:00
sebmarkbage c88a1f2c26 Add moveBefore Experiment (#31596)
A long standing issue for React has been that if you reorder stateful
nodes, they may lose their state and reload. The thing moving loses its
state. There's no way to solve this in general where two stateful nodes
swap.

The [`moveBefore()`
proposal](https://chromestatus.com/feature/5135990159835136?gate=5177450351558656)
has now moved to
[intent-to-ship](https://groups.google.com/a/chromium.org/g/blink-dev/c/YE_xLH6MkRs/m/_7CD0NYMAAAJ).
This function is kind of like `insertBefore` but preserves state.

There's [a demo here](https://state-preserving-atomic-move.glitch.me/).
Ideally we'd port this demo to a fixture so we can try it.

Currently this flag is always off - even in experimental. That's because
this is still behind a Chrome flag so it's a little early to turn it on
even in experimental. So you need a custom build. It's on in RN but only
because it doesn't apply there which makes it easier to tell that it's
safe to ship once it's on everywhere else.

The other reason it's still off is because there's currently a semantic
breaking change. `moveBefore()` errors if both nodes are disconnected.
That happens if we're inside a completely disconnected React root.
That's not usually how you should use React because it means effects
can't read layout etc. However, it is currently supported. To handle
this we'd have to try/catch the `moveBefore` to handle this case but we
hope this semantic will change before it ships. Before we turn this on
in experimental we either have to wait for the implementation to not
error in the disconnected-disconnected case in Chrome or we'd have to
add try/catch.

DiffTrain build for [aba370f1e4](https://github.com/facebook/react/commit/aba370f1e45d21f19f33c04c33fc99fb3d0109e5)
2024-11-22 10:37:34 -08:00
poteto b78a8b16c9 [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:00 -08:00
poteto 2183a80813 [crud] Enable on RTR FB builds (#31590)
DiffTrain build for [64f89510af](https://github.com/facebook/react/commit/64f89510af244b1d812de7a74e161975d99ad3e1)
2024-11-19 14:32:14 -08:00
poteto b7dde5be16 [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:00 -08:00
poteto 729d103900 [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:13 -08:00
sebmarkbage 3730bd50d2 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:38 -08:00
poteto 19e9146485 [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