@@ -341,7 +341,6 @@ let hasUncaughtError = false;
341
341
let firstUncaughtError = null;
342
342
let legacyErrorBoundariesThatAlreadyFailed: Set< mixed > | null = null;
343
343
344
- let rootDoesHavePassiveEffects: boolean = false;
345
344
let rootWithPendingPassiveEffects: FiberRoot | null = null;
346
345
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
347
346
let pendingPassiveEffectsLanes: Lanes = NoLanes;
@@ -1865,6 +1864,22 @@ function commitRootImpl(root, renderPriorityLevel) {
1865
1864
// times out.
1866
1865
}
1867
1866
1867
+ // If there are pending passive effects, schedule a callback to process them.
1868
+ // Do this as early as possible, so it is queued before anything else that
1869
+ // might get scheduled in the commit phase. (See #16714.)
1870
+ const rootDoesHavePassiveEffects =
1871
+ ( finishedWork . subtreeFlags & PassiveMask ) !== NoFlags ||
1872
+ ( finishedWork . flags & PassiveMask ) !== NoFlags ;
1873
+ if ( rootDoesHavePassiveEffects ) {
1874
+ rootWithPendingPassiveEffects = root ;
1875
+ pendingPassiveEffectsLanes = lanes ;
1876
+ pendingPassiveEffectsRenderPriority = renderPriorityLevel ;
1877
+ scheduleCallback ( NormalSchedulerPriority , ( ) => {
1878
+ flushPassiveEffects ( ) ;
1879
+ return null ;
1880
+ } ) ;
1881
+ }
1882
+
1868
1883
// Check if there are any effects in the whole tree.
1869
1884
// TODO: This is left over from the effect list implementation, where we had
1870
1885
// to check for the existence of `firstEffect` to satsify Flow. I think the
@@ -1880,20 +1895,6 @@ function commitRootImpl(root, renderPriorityLevel) {
1880
1895
NoFlags ;
1881
1896
1882
1897
if ( subtreeHasEffects || rootHasEffect ) {
1883
- // If there are pending passive effects, schedule a callback to process them.
1884
- if (
1885
- ( finishedWork . subtreeFlags & PassiveMask ) !== NoFlags ||
1886
- ( finishedWork . flags & PassiveMask ) !== NoFlags
1887
- ) {
1888
- if ( ! rootDoesHavePassiveEffects ) {
1889
- rootDoesHavePassiveEffects = true ;
1890
- scheduleCallback ( NormalSchedulerPriority , ( ) => {
1891
- flushPassiveEffects ( ) ;
1892
- return null ;
1893
- } ) ;
1894
- }
1895
- }
1896
-
1897
1898
let previousLanePriority ;
1898
1899
if ( decoupleUpdatePriorityFromScheduler ) {
1899
1900
previousLanePriority = getCurrentUpdateLanePriority ( ) ;
@@ -2010,17 +2011,6 @@ function commitRootImpl(root, renderPriorityLevel) {
2010
2011
}
2011
2012
}
2012
2013
2013
- const rootDidHavePassiveEffects = rootDoesHavePassiveEffects ;
2014
-
2015
- if ( rootDoesHavePassiveEffects ) {
2016
- // This commit has passive effects. Stash a reference to them. But don't
2017
- // schedule a callback until after flushing layout work.
2018
- rootDoesHavePassiveEffects = false ;
2019
- rootWithPendingPassiveEffects = root ;
2020
- pendingPassiveEffectsLanes = lanes ;
2021
- pendingPassiveEffectsRenderPriority = renderPriorityLevel ;
2022
- }
2023
-
2024
2014
// Read this again, since an effect might have updated it
2025
2015
remainingLanes = root . pendingLanes ;
2026
2016
@@ -2047,13 +2037,13 @@ function commitRootImpl(root, renderPriorityLevel) {
2047
2037
}
2048
2038
2049
2039
if ( __DEV__ && enableDoubleInvokingEffects ) {
2050
- if ( ! rootDidHavePassiveEffects ) {
2040
+ if ( ! rootDoesHavePassiveEffects ) {
2051
2041
commitDoubleInvokeEffectsInDEV ( root . current , false ) ;
2052
2042
}
2053
2043
}
2054
2044
2055
2045
if ( enableSchedulerTracing ) {
2056
- if ( ! rootDidHavePassiveEffects ) {
2046
+ if ( ! rootDoesHavePassiveEffects ) {
2057
2047
// If there are no passive effects, then we can complete the pending interactions.
2058
2048
// Otherwise, we'll wait until after the passive effects are flushed.
2059
2049
// Wait to do this until after remaining work has been scheduled,
@@ -2356,16 +2346,6 @@ function commitMutationEffectsDeletions(
2356
2346
}
2357
2347
}
2358
2348
2359
- export function schedulePassiveEffectCallback ( ) {
2360
- if ( ! rootDoesHavePassiveEffects ) {
2361
- rootDoesHavePassiveEffects = true ;
2362
- scheduleCallback ( NormalSchedulerPriority , ( ) => {
2363
- flushPassiveEffects ( ) ;
2364
- return null ;
2365
- } ) ;
2366
- }
2367
- }
2368
-
2369
2349
export function flushPassiveEffects ( ) : boolean {
2370
2350
// Returns whether passive effects were flushed.
2371
2351
if ( pendingPassiveEffectsRenderPriority !== NoSchedulerPriority ) {
0 commit comments