Commit Graph

1150 Commits

Author SHA1 Message Date
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
sebmarkbage 2be2b99db8 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:00 -08:00
sebmarkbage 654531ffba 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 23caea5384 (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:24 -08:00
acdlite 5834fcd199 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:17 -08:00
rickhanlonii a6bc139e0e Fix continuation bug (#31434)
## Overview

In `scheduleTaskForRootDuringMicrotask` we clear `root.callbackNode` if
the work loop is [suspended waiting on
data](https://github.com/facebook/react/blob/ac3ca097aeecae8fe3ec7f9b286307a923676518/packages/react-reconciler/src/ReactFiberRootScheduler.js#L338).

But we don't null check `root.callbackNode` before returning a
continuation in `performWorkOnRootViaSchedulerTask` where
`scheduleTaskForRootDuringMicrotask` is synchronously called, causing an
infinite loop when the only thing in the queue is something suspended
waiting on data.

This essentially restores the behavior from here:
https://github.com/facebook/react/pull/26328/files#diff-72ff2175ae3569037f0b16802a41b0cda2b2d66bb97f2bda78ed8445ed487b58L1168

Found by investigating the failures for
https://github.com/facebook/react/pull/31417

## TODO
- add a test

---------

Co-authored-by: Joe Savona <joesavona@fb.com>

DiffTrain build for [b836de613d](https://github.com/facebook/react/commit/b836de613d66ff36574af95cb93ad15fd743d1f4)
2024-11-11 14:32:54 -08:00
jackpope 1decb40323 Make prerendering always non-blocking with fix (#31452)
We've previously failed to land this change due to some internal apps
seeing infinite render loops due to external store state updates during
render. It turns out that since the `renderWasConcurrent` var was moved
into the do block, the sync render triggered from the external store
check was stuck with a `RootSuspended` `exitStatus`. So this is not
unique to sibling prerendering but more generally related to how we
handle update to a sync external store during render.

We've tested this build against local repros which now render without
crashes. We will try to add a unit test to cover the scenario as well.

---------

Co-authored-by: Andrew Clark <git@andrewclark.io>
Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>

DiffTrain build for [989af12f72](https://github.com/facebook/react/commit/989af12f72080c17db03ead91d99b6394a215564)
2024-11-08 09:45:51 -08:00
sammy-SC 4cc587fdf6 Update React Native shims to use export syntax (#31426)
## Summary

I'm working to get the main `react-native` package parsable by modern
Flow tooling (both `flow-bundler`, `flow-api-translator`), and one
blocker is legacy `module.exports` syntax. This diff updates files which
are [synced to
`react-native`](https://github.com/facebook/react-native/tree/main/packages/react-native/Libraries/Renderer/shims)
from this repo.

## How did you test this change?

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

DiffTrain build for [5c56b873ef](https://github.com/facebook/react/commit/5c56b873efb300b4d1afc4ba6f16acf17e4e5800)
2024-11-07 07:01:19 -08:00
sophiebits f2a54ca827 Remove unused lastFullyObservedContext (#31435)
DiffTrain build for [66855b9637](https://github.com/facebook/react/commit/66855b96378daedb1405e83f2365e0d90966ea0e)
2024-11-06 07:42:34 -08:00
kassens e7265498ae Back out "[bundles] stop building legacy Paper renderer (#31429)" (#31437)
Backs out the 2 related commits:
-
https://github.com/facebook/react/commit/f8f6e1a21a1cac64cf6faf666367d641b2d8b171
-
https://github.com/facebook/react/commit/6c0f37f94b020279fb5ada70facc008fccb7172e

Since I only realized when syncing that we need the version of `react`
and the legacy renderer to match.

While I investigate if there's anything we can do to work around that
while preserving the legacy renderer, this unblocks the sync.

DiffTrain build for [314968561b](https://github.com/facebook/react/commit/314968561b547957c76c9d7be3620e38f87770d4)
2024-11-06 06:48:40 -08:00
kassens e3bb0848ec [bundles] update GitHub actions for commit build branch (#31432)
This is a followup to
https://github.com/facebook/react/commit/6c0f37f94b020279fb5ada70facc008fccb7172e
to unblock the job.

DiffTrain build for [f8f6e1a21a](https://github.com/facebook/react/commit/f8f6e1a21a1cac64cf6faf666367d641b2d8b171)
2024-11-05 13:11:34 -08:00
kassens c53145cf89 Remove enableRefAsProp feature flag (#30346)
The flag is fully rolled out.

DiffTrain build for [07aa494432](https://github.com/facebook/react/commit/07aa494432e97f63fca9faf2fad6f76fead31063)
2024-11-04 11:38:26 -08:00
yungsters eeb33289ca Fix Ref Lifecycles in Hidden Subtrees (#31379)
## Summary

We're seeing certain situations in React Native development where ref
callbacks in `<Activity mode="hidden">` are sometimes invoked exactly
once with `null` without ever being called with a "current" value.

This violates the contract for refs because refs are expected to always
attach before detach (and to always eventually detach after attach).
This is *particularly* bad for refs that return cleanup functions,
because refs that return cleanup functions expect to never be invoked
with `null`. This bug causes such refs to be invoked with `null`
(because since `safelyAttachRef` was never called, `safelyDetachRef`
thinks the ref does not return a cleanup function and invokes it with
`null`).

This fix makes use of `offscreenSubtreeWasHidden` in
`commitDeletionEffectsOnFiber`, similar to how
https://github.com/facebook/react/commit/ec52a5698e2dfea7050a0b015f0b79abfb2d81b7
did this for `commitDeletionEffectsOnFiber`.

## How did you test this change?

We were able to isolate the repro steps to isolate the React Native
experimental changes. However, the repro steps depend on Fast Refresh.

```
function callbackRef(current) {
  // Called once with `current` as null, upon triggering Fast Refresh.
}

<Activity mode="hidden">
  <View ref={callbackRef} />;
</Activity>
```

Ideally, we would have a unit test that verifies this behavior without
Fast Refresh. (We have evidence that this bug occurs without Fast
Refresh in real product implementations. However, we have not
successfully deduced the root cause, yet.)

This PR currently includes a unit test that reproduces the Fast Refresh
scenario, which is also demonstrated in this CodeSandbox:
https://codesandbox.io/p/sandbox/hungry-darkness-33wxy7

Verified unit tests pass:

```
$ yarn
$ yarn test
# Run with `-r=www-classic` for `enableScopeAPI` tests.
$ yarn test -r=www-classic
```

Verified on the internal React Native development branch that the bug no
longer repros.

---------

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

DiffTrain build for [ea3ac58669](https://github.com/facebook/react/commit/ea3ac586693014e882655728fc8396ecb1d6cf6e)
2024-10-31 13:32:06 -07:00
sebmarkbage 0fb655b159 Capture the source and not just the stack on first seen error (#31367)
Otherwise we can't capture the owner stack at the right location when
there's a rethrow.

DiffTrain build for [0bc3074873](https://github.com/facebook/react/commit/0bc30748730063e561d87a24a4617526fdd38349)
2024-10-28 14:07:10 -07:00
jackpope 2ef3590635 Revert "[Re-land] Make prerendering always non-blocking (#31268)" (#31355)
This reverts commit 6c4bbc7832.

It looked like the bug we found on the original land was related to
broken product code. But through landing #31268 we found additional bugs
internally. Since disabling the feature flag does not fix the bugs, we
have to revert again to unblock the sync. We can continue to debug with
our internal build.

DiffTrain build for [cae764ce81](https://github.com/facebook/react/commit/cae764ce81b1bd6c418e9e23651794b6b09208e8)
2024-10-25 09:24:35 -07:00
SamChou19815 bd06b969c2 [flow] Eliminate usage of more than 1-arg React.AbstractComponent in React codebase (#31314)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

In order to adopt react 19's ref-as-prop model, Flow needs to eliminate
all the places where they are treated differently.
`React.AbstractComponent` is the worst example of this, and we need to
eliminate it.

This PR eliminates them from the react repo, and only keeps the one that
has 1 argument of props.

## How did you test this change?

yarn flow

DiffTrain build for [45804af18d](https://github.com/facebook/react/commit/45804af18d589fd2c181f3b020f07661c46b73ea)
2024-10-21 16:26:07 -07:00
sebmarkbage 750a0e4d65 Audit try/finally around console patching (#31286)
Otherwise if something errors they can be left patched.

[Review without
whitespace](https://github.com/facebook/react/pull/31286/files?w=1)

DiffTrain build for [b8ae38f88b](https://github.com/facebook/react/commit/b8ae38f88b70f8a0ea96421a4355266aafefee7f)
2024-10-18 09:14:24 -07:00
yungsters d4ef1bcd0c Delete __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED from React Native Renderer (#31276)
## Summary

The React Native Renderer exports a
`__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED` property with a
single method that has no remaining call sites:
`computeComponentStackForErrorReporting`

This PR cleans up this unused export.

## How did you test this change?

```
$ yarn
$ yarn flow fabric
$ yarn test
```

DiffTrain build for [a3d9ea05bf](https://github.com/facebook/react/commit/a3d9ea05bf01f3c3d7aedc2d938c581ad11fd14a)
2024-10-16 11:27:56 -07:00
jackpope 6ee7d9d904 [Re-land] Make prerendering always non-blocking (#31268)
Follows https://github.com/facebook/react/pull/31238

___

This is a partial re-land of
https://github.com/facebook/react/pull/31056. We saw breakages surface
after the original land and had to revert. Now that they've been fixed,
let's try this again. This time we'll split up the commits to give us
more control of testing and rollout internally.

Original PR: https://github.com/facebook/react/pull/31056
Original Commit:
https://github.com/facebook/react/pull/31056/commits/4c71025d8d1bd46344ad793e7ed3049d24f7395a
Revert PR: https://github.com/facebook/react/pull/31080

Commit description:

> When a synchronous update suspends, and we prerender the siblings, the
prerendering should be non-blocking so that we can immediately restart
once the data arrives.
>
> This happens automatically when there's a Suspense boundary, because
we immediately commit the boundary and then proceed to a Retry render,
which are always concurrent. When there's not a Suspense boundary, there
is no Retry, so we need to take care to switch from the synchronous work
loop to the concurrent one, to enable time slicing.

Co-authored-by: Andrew Clark <git@andrewclark.io>

DiffTrain build for [6c4bbc7832](https://github.com/facebook/react/commit/6c4bbc783286bf6eebd9927cb52e8fec5ad4dd74)
2024-10-15 13:55:45 -07:00