Commit Graph

416 Commits

Author SHA1 Message Date
Sebastian Markbåge
fe21c947c8
[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.
2025-01-02 13:02:22 -05:00
Sebastian "Sebbie" Silbermann
518d06d26a
Turn off enableYieldingBeforePassive (#31857) 2024-12-19 20:43:01 +01:00
Ricky
faf6c4dfdc
[flags] Remove debugRenderPhaseSideEffectsForStrictMode (#31839)
This is enabled everywhere, we can just use the inline `__DEV__` checks.
2024-12-18 17:51:12 -05:00
Ricky
74dd2da9ac
[flags] Remove enableModernStrictMode (#31838)
This is enabled everywhere.
2024-12-18 14:45:37 -05:00
Sebastian Markbåge
facec3ee71
[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"
/>
2024-12-17 17:01:31 -05:00
Jack Pope
34ee3919c3
Clean up enableLazyContextPropagation (#31810)
This flag has shipped everywhere, let's clean it up.
2024-12-17 11:56:00 -05:00
Jack Pope
909ed63e0a
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.
2024-12-16 12:32:07 -05:00
Ricky
e06c72fcf4
[flags] Cleanup enableCache (#31778)
This is landed everywhere
2024-12-15 12:34:08 -05:00
Ricky
2d320563f3
[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.
2024-12-15 12:16:10 -05:00
Sebastian Markbåge
d1dd7feabc
[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"
/>
2024-12-14 13:46:21 -05:00
Ricky
9e2c233139
[flags] Delete enableSuspenseAvoidThisFallbackFizz (#31779)
We're not shipping `enableSuspenseAvoidThisFallback` and the fizz flag
is already off so we can delete it.
2024-12-14 13:05:17 -05:00
Ricky
2e25ee373d
[flags] Cleanup enableUseMemoCacheHook (#31767)
Based off https://github.com/facebook/react/pull/31766

This has already landed everywhere.
2024-12-14 11:11:04 -05:00
Ricky
152080276c
Remove enableFlightReadableStream (#31766)
Base: https://github.com/facebook/react/pull/31765

Landed everywhere
2024-12-13 16:39:13 -05:00
Ricky
4996a8fa5c
Remove enableFilterEmptyStringAttributesDOM (#31765)
Base off https://github.com/facebook/react/pull/31764

This has landed everywhere
2024-12-13 16:30:10 -05:00
Ricky
3ad17ecd31
Remove enableComponentStackLocations (#31764)
This has landed everywhere
2024-12-13 15:52:42 -05:00
Ricky
08dfd0b805
Remove enableBinaryflight (#31759)
Based off https://github.com/facebook/react/pull/31757

This has landed everywhere.
2024-12-13 14:50:13 -05:00
Ricky
ef63718a27
Remove enableAsyncActions (#31757)
Based on https://github.com/facebook/react/pull/31756

This is landed everywhere
2024-12-13 13:58:18 -05:00
Ricky
fb12845d77
Remove disableIEWorkarounds (#31756)
Based off https://github.com/facebook/react/pull/31755

This is landed everywhere.
2024-12-13 12:26:40 -05:00
Ricky
4dff0e62b2
Remove consoleManagedByDevToolsDuringStrictMode (#31755)
This is enabled everywhere except the test renderers, which don't use
it.
2024-12-13 11:05:10 -05:00
Sebastian Markbåge
d5e8f79cf4
[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).
2024-12-12 23:06:07 -05:00
Sebastian Markbåge
aba370f1e4
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.
2024-11-22 13:24:29 -05:00
lauren
7dd6b9e68a
[crud] Add enableUseResourceEffectHook flag (#31556)
Adds a new feature flag for `enableUseResourceEffectHook`.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31556).
* #31523
* #31557
* __->__ #31556
* #31555
2024-11-15 17:49:42 -05:00
Andrew Clark
988e217670
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.
2024-11-14 11:48:14 -05:00
Jan Kassens
e1378902bb
[string-refs] cleanup string ref code (#31443) 2024-11-06 14:00:10 -05:00
Jan Kassens
d1f04722d6
[string-refs] remove enableLogStringRefsProd flag (#31414)
We no longer need this production logging.
2024-11-06 09:00:49 -05:00
Jan Kassens
07aa494432
Remove enableRefAsProp feature flag (#30346)
The flag is fully rolled out.
2024-11-04 14:30:58 -05:00
Josh Story
7c8e5e7ab8
Reenable lazy context propagation (#31405)
Reverts facebook/react#31403 to reenable lazy context propagation

The disabling was to produce a build that could help track down whether
this flag is causing a possibly related bug in transitions but we don't
intend to disable it just fix forward once we figure out what the
problem is
2024-11-01 15:17:51 -07:00
Josh Story
16409d0560
temporarily disable lazy context propagation (#31403)
disables lazy context propagation in oss to help determine if it is
causing bugs in startTransition. Will reenable after cutting a canary
release with this flag disabled
2024-11-01 15:16:26 -07:00
Jan Kassens
5636fad840
[string-refs] log string ref from prod (#31161)
If passed as a feature flag, this calls the configured function when a
string ref is used even from prod code to find the last usages.
2024-10-10 18:12:47 -04:00
Jan Kassens
de43d560a8
[cleanup] remove flag enableAddPropertiesFastPath (#31062)
The experiment was tested internally and rolled out, replacing the flag
with `true`.
2024-10-09 16:46:35 -04:00
Jack Pope
d8c90fa48d
Disable infinite render loop detection (#31088)
We're seeing issues with this feature internally including bugs with
sibling prerendering and errors that are difficult for developers to
action on. We'll turn off the feature for the time being until we can
improve the stability and ergonomics.

This PR does two things:
- Turn off `enableInfiniteLoopDetection` everywhere while leaving it as
a variant on www so we can do further experimentation.
- Revert https://github.com/facebook/react/pull/31061 which was a
temporary change for debugging. This brings the feature back to
baseline.
2024-10-01 11:00:57 -04:00
Sebastian Markbåge
0eab377a96
Add enableComponentPerformanceTrack Flag (#30960)
This flag will be used to gate a new timeline profiler that's integrate
with the Performance Tab and the new performance.measure extensions in
Chrome.

It replaces the existing DevTools feature so this disables
enableSchedulingProfiler when it is enabled since they can interplay in
weird ways potentially.

This means that experimental React now disable scheduling profiler and
enables this new approach.
2024-09-16 11:09:40 -04:00
Jan Kassens
d3d4d3a46b
Call cleanup of insertion effects when hidden (#30954)
Insertion effects do not unmount when a subtree is removed while
offscreen.

Current behavior for an insertion effect is if the component goes

- *visible -> removed:* calls insertion effect cleanup
- *visible -> offscreen -> removed:* insertion effect cleanup is never
called

This makes it so we always call insertion effect cleanup when removing
the component.

Likely also fixes https://github.com/facebook/react/issues/26670

---------

Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
2024-09-13 16:18:14 -04:00
Sebastian Markbåge
89b445709d
Enable lazy context propagation (#30935)
Last I heard this was great so not sure there are any more blockers to
just include it in 19?
2024-09-12 13:01:56 -04:00
Josh Story
94e652d505
disable enableSiblingPrerendering in experimental channel (#30952)
Disables `enableSiblingPrerendering` in the experimental builds until
the feature is tested at Meta first.
2024-09-12 09:33:20 -07:00
Sebastian Markbåge
4f60494156
[Flight] Ship DEV-only enableServerComponentLogs flag in Stable/Canary (#30847)
To recap. This only affects DEV and RSC. It patches console on the
server in DEV (similar to how React DevTools already does and what we
did for the double logging). Then replays those logs with a `[Server]`
badge on the client so you don't need a server terminal open.

This has been on for over 6 months now in our experimental channel and
we've had a lot of coverage in Next.js due to various experimental flags
like taint and ppr.

It's non-invasive in that even if something throws we just serialize
that as an unknown value.

The main feedback we've gotten was:

- The serialization depth wasn't deep enough which I addressed in #30294
and haven't really had any issues since. This could still be an issue or
the inverse that you serialize too many logs that are also too deep.
This is not so much an issue with intentional logging and things like
accidental errors don't typically have unbounded arguments (e.g. React
errors are always string arguments). The ideal would be some way to
retain objects and then load them on-demand but that needs more
plumbing. Which can be later.
- The other was that double logging on the server is annoying if the
same terminal does both the RSC render and SSR render which was
addressed in #30207. It is now off by default in node/edge-builds of the
client, on by default in browser builds. With the `replayConsole` option
to either opt-in or out.

We've reached a good spot now I think.

These are better with `enableOwnerStacks` but that's a separate track
and not needed.

The only thing to document here, other than maybe that we're doing it,
is the `replayConsole` option but that's part of the RSC renderers that
themselves are not documented so nowhere to document it.
2024-08-30 15:11:57 -04:00
Andrew Clark
eb3ad065a1
Feature flag: enableSiblingPrerendering (#30761)
Adds a new feature flag for an upcoming experiment.

No implementation yet.
2024-08-22 10:17:19 -04:00
Josh Story
7b41cdc093
[Flight][Static] Implement halting a prerender behind enableHalt (#30705)
enableHalt turns on a mode for flight prerenders where aborts are
treated like infinitely stalled outcomes while still completing the
prerender. For regular tasks we simply serialize the slot as a promise
that never settles. For ReadableStream, Blob, and Async Iterators we
just never advance the serialization so they remain unfinished when
consumed on the client.

When enableHalt is turned on aborts of prerenders will halt rather than
error. The abort reason is forwarded to the upstream produces of the
aforementioned async iterators, blobs, and ReadableStreams. In the
future if we expose a signal that you can consume from within a render
to cancel additional work the abort reason will also be forwarded there
2024-08-16 14:21:57 -07:00
Jan Kassens
65903583d2
Remove flag enableUseDeferredValueInitialArg (#30595)
This is enabled everywhere for a while and I don't think we'd be backing
this out of 19. Seems like it's good to clean up to me.
2024-08-05 11:25:05 -04:00
Jan Kassens
5fb67fa25c
Cloned flag to avoid extra clones in persistent renderer (#27647)
Persistent renderers used the `Update` effect flag to check if a subtree
needs to be cloned. In some cases, that causes extra renders, such as
when a layout effect is triggered which only has an effect on the JS
side, but doesn't update the host components.

It's been a bit tricky to find the right places where this needs to be
set and I'm not 100% sure I got all the cases even though the tests
passed.
2024-08-01 15:11:19 -04:00
Jan Kassens
6b82f3c904
[RN] experiment to move Fabric completeWork to the commit phase (#30513)
There is currently a mismatch in how the persistent mode JS API and the
Fabric native code interpret `completeRoot`.

This is a short-lived experiment to see the effect of moving the Fabric
`completeRoot` call from `finalizeContainerChildren` to
`replaceContainerChildren` which in some cases does not get called.
2024-07-29 18:38:55 -04:00
Jack Pope
397646ad51
Update enableLazyContextPropagation flag (#30514)
- Flag set to true for FB
- Flag set to experimental for OSS
2024-07-29 16:50:28 -04:00
Jack Pope
1350a85980
Add unstable context bailout for profiling (#30407)
**This API is not intended to ship. This is a temporary unstable hook
for internal performance profiling.**

This PR exposes `unstable_useContextWithBailout`, which takes a compare
function in addition to Context. The comparison function is run to
determine if Context propagation and render should bail out earlier.
`unstable_useContextWithBailout` returns the full Context value, same as
`useContext`.

We can profile this API against `useContext` to better measure the cost
of Context value updates and gather more data around propagation and
render performance.

The bailout logic and test cases are based on
https://github.com/facebook/react/pull/20646

Additionally, this implementation allows multiple values to be compared
in one hook by returning a tuple to avoid requiring additional Context
consumer hooks.
2024-07-26 14:38:24 -04:00
Jack Pope
14a4699ff1
Remove allowConcurrentByDefault flag (#30445)
Following https://github.com/facebook/react/pull/30436

Concurrent by default strategy has been unshipped. Here we clean up the
`allowConcurrentByDefault` path and related logic/tests.

For now, this keeps the `concurrentUpdatesByDefaultOverride` argument in
`createContainer` and `createHydrationContainer` and ignores the value
to prevent more breaking changes to `react-reconciler` in the RC stage.
2024-07-25 11:59:50 -04:00
Jack Pope
e902c45caf
Remove forceConcurrentByDefaultForTesting flag (#30436)
Concurrent by default has been unshipped! Let's clean it up.

Here we remove `forceConcurrentByDefaultForTesting`, which allows us to
run tests against both concurrent strategies. In the next PR, we'll
remove the actual concurrent by default code path.
2024-07-24 10:17:33 -04:00
Jan Kassens
d025ddd3b9
Set enableFastJSX flag to true (#30343)
When these to diffs are landed, we can merge this

- [x] D59772879
- [x] D59773043
2024-07-22 11:50:35 -04:00
Jan Kassens
af28f480e8
Feature flag to disable legacy context for function components (#30319)
While the goal is to remove legacy context completely, I think we can
already land the removal of legacy context for function components. I
didn't even know this feature existed until reading the code recently.

The win is just a couple of property lookups on function renders, but it
trims down the API already as the full removal will likely still take a
bit more time.

www: Starting with enabled test renderer and a feature flag for
production rollout.

RN: Not enabled, will follow up on this.
2024-07-11 16:21:12 -04:00
Jan Kassens
fe9828954a
Experiment with using an object literal for Fiber creation (#28734)
Object literals should be faster at least on React Native with Hermes as
the JS engine.
It might also be interesting to confirm the old comments in this file
from years ago are even still valid. Creating an object from a literal
should be a simpler operation.

It's a bit unfortunate that this introduces a bunch of copied code, but
since we rearely update the fields on fibers, this seems like an okay
tradeoff for a hot code path. An alternative would be some sort of macro
system, but that doesn't seem worth the extra complexity.
2024-07-10 16:42:08 -04:00
Jack Pope
c21bcd627b
Clean up enableUnifiedSyncLane flag (#30062)
`enableUnifiedSyncLane` now passes everywhere. Let's clean it up

Implemented with https://github.com/facebook/react/pull/27646

Flag enabled with https://github.com/facebook/react/pull/27646,
https://github.com/facebook/react/pull/28269,
https://github.com/facebook/react/pull/29052
2024-06-24 11:18:22 -04:00
Dmytro Rykun
eb259b5d3b
Add enableShallowPropDiffing feature flag (#29664)
## Summary

We currently do deep diffing for object props, and also use custom
differs, if they are defined, for props with custom attribute config.

The idea is to simply do a `===` comparison instead of all that work. We
will do less computation on the JS side, but send more data to native.

The hypothesis is that this change should be neutral in terms of
performance. If that's the case, we'll be able to get rid of custom
differs, and be one step closer to deleting view configs.

This PR adds the `enableShallowPropDiffing` feature flag to support this
experiment.

## How did you test this change?

With `enableShallowPropDiffing` hardcoded to `true`:
```
yarn test packages/react-native-renderer
```
This fails on the following test cases:
- should use the diff attribute
- should do deep diffs of Objects by default
- should skip deeply-nested changed functions

Which makes sense with this change. These test cases should be deleted
if the experiment is shipped.
2024-06-05 15:07:58 +01:00