-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nesting of React.startTransition and ReactDOM.flushSync #21136
Support nesting of React.startTransition and ReactDOM.flushSync #21136
Conversation
Currently we track event priorities in two different places: - For transitions, we use the ReactCurrentBatchConfig object, which lives in the secret internals object of the isomorphic package. This is how the hook-less `startTransition` works. - For other types of events, we use a module-level variable in ReactEventPriorities, which is owned by the renderer. The problem with this approach is if both priorities are set, we don't know which one takes precedence. For example, what happens if wrap an update in both `ReactDOM.flushSync` and `React.startTransition`? The desired behavior is that we use the priority of whichever wrapper is closer on the stack. So if `flushSync` is called inside of `startTransition`, then we should use sync priority; if it's the other way around, we should use transition priority. To implement this, I updated the ReactEventPriorities module to track priority on the ReactCurrentBatchConfig object instead of in a module- level variable. Now when multiple event wrappers are nested, the inner- most wrapper wins.
Comparing: 0853aab...16a8eca Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
6d7dc04
to
f2a4e8c
Compare
9d2d689
to
16a8eca
Compare
// boundary: importing from a shared module would give a false sense of | ||
// DRYness, because it's theoretically possible for for the renderer and | ||
// the isomorphic package to be out of sync. We don't fully support that, but we | ||
// should try (within reason) to be resilient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, copying over gives a false sense of safety since if the renderer and isomorphic are out of sync, this could also be wrong.
Closed in favor of #21149 |
Currently we track event priorities in two different places:
startTransition
works.The problem with this approach is if both priorities are set, we don't know which one takes precedence. For example, what happens if wrap an update in both
ReactDOM.flushSync
andReact.startTransition
?The desired behavior is that we use the priority of whichever wrapper is closer on the stack. So if
flushSync
is called inside ofstartTransition
, then we should use sync priority; if it's the other way around, we should use transition priority.To implement this, I updated the ReactEventPriorities module to track priority on the ReactCurrentBatchConfig object instead of in a module- level variable. Now when multiple event wrappers are nested, the innermost wrapper wins.