Skip to content

Commit b47223f

Browse files
committed
[Fiber] Don't work on scheduled tasks while we're in an async commit but flush it eagerly if we're sync (facebook#31987)
This is a follow up to facebook#31930 and a prerequisite for facebook#31975. With View Transitions, the commit phase becomes async which means that other work can sneak in between. We need to be resilient to that. This PR first refactors the flushMutationEffects and flushLayoutEffects to use module scope variables to track its arguments so we can defer them. It shares these with how we were already doing it for flushPendingEffects. We also track how far along the commit phase we are so we know what we have left to flush. Then callers of flushPassiveEffects become flushPendingEffects. That helper synchronously flushes any remaining phases we've yet to commit. That ensure that things are at least consistent if that happens. Finally, when we are using a scheduled task, we don't do any work. This ensures that we're not flushing any work too early if we could've deferred it. This still ensures that we always do flush it before starting any new work on any root so new roots observe the committed state. There are some unfortunate effects that could happen from allowing things to flush eagerly. Such as if a flushSync sneaks in before startViewTransition, it'll skip the animation. If it's during a suspensey font it'll start the transition before the font has loaded which might be better than breaking flushSync. It'll also potentially flush passive effects inside the startViewTransition which should typically be ok. DiffTrain build for [defffdb](facebook@defffdb)
1 parent 898a6ad commit b47223f

34 files changed

+6420
-5970
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
301a18a6afeaea9c6113d7e459025ba69f436b24
1+
defffdbba43f89b95d9f67a4fb0fa146c1211734
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
301a18a6afeaea9c6113d7e459025ba69f436b24
1+
defffdbba43f89b95d9f67a4fb0fa146c1211734

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ __DEV__ &&
19421942
exports.useTransition = function () {
19431943
return resolveDispatcher().useTransition();
19441944
};
1945-
exports.version = "19.1.0-www-classic-301a18a6-20250106";
1945+
exports.version = "19.1.0-www-classic-defffdbb-20250106";
19461946
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19471947
"function" ===
19481948
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ __DEV__ &&
19421942
exports.useTransition = function () {
19431943
return resolveDispatcher().useTransition();
19441944
};
1945-
exports.version = "19.1.0-www-modern-301a18a6-20250106";
1945+
exports.version = "19.1.0-www-modern-defffdbb-20250106";
19461946
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19471947
"function" ===
19481948
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.1.0-www-classic-301a18a6-20250106";
633+
exports.version = "19.1.0-www-classic-defffdbb-20250106";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
630630
exports.useTransition = function () {
631631
return ReactSharedInternals.H.useTransition();
632632
};
633-
exports.version = "19.1.0-www-modern-301a18a6-20250106";
633+
exports.version = "19.1.0-www-modern-defffdbb-20250106";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.1.0-www-classic-301a18a6-20250106";
637+
exports.version = "19.1.0-www-classic-defffdbb-20250106";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
634634
exports.useTransition = function () {
635635
return ReactSharedInternals.H.useTransition();
636636
};
637-
exports.version = "19.1.0-www-modern-301a18a6-20250106";
637+
exports.version = "19.1.0-www-modern-defffdbb-20250106";
638638
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
639639
"function" ===
640640
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)