@@ -391,6 +391,7 @@ let rootWithPendingPassiveEffects: FiberRoot | null = null;
391391let pendingPassiveEffectsLanes: Lanes = NoLanes;
392392let pendingPassiveProfilerEffects: Array< Fiber > = [];
393393let pendingPassiveEffectsRemainingLanes: Lanes = NoLanes;
394+ let pendingPassiveTransitions: Array< Transition > | null = null;
394395
395396// Use these to prevent an infinite loop of nested updates
396397const NESTED_UPDATE_LIMIT = 50;
@@ -1074,7 +1075,11 @@ function finishConcurrentRender(root, exitStatus, lanes) {
10741075 case RootErrored : {
10751076 // We should have already attempted to retry this tree. If we reached
10761077 // this point, it errored again. Commit it.
1077- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1078+ commitRoot (
1079+ root ,
1080+ workInProgressRootRecoverableErrors ,
1081+ workInProgressTransitions ,
1082+ ) ;
10781083 break ;
10791084 }
10801085 case RootSuspended : {
@@ -1114,14 +1119,23 @@ function finishConcurrentRender(root, exitStatus, lanes) {
11141119 // lower priority work to do. Instead of committing the fallback
11151120 // immediately, wait for more data to arrive.
11161121 root . timeoutHandle = scheduleTimeout (
1117- commitRoot . bind ( null , root , workInProgressRootRecoverableErrors ) ,
1122+ commitRoot . bind (
1123+ null ,
1124+ root ,
1125+ workInProgressRootRecoverableErrors ,
1126+ workInProgressTransitions ,
1127+ ) ,
11181128 msUntilTimeout ,
11191129 ) ;
11201130 break ;
11211131 }
11221132 }
11231133 // The work expired. Commit immediately.
1124- commitRoot ( root , workInProgressRootRecoverableErrors) ;
1134+ commitRoot (
1135+ root ,
1136+ workInProgressRootRecoverableErrors ,
1137+ workInProgressTransitions ,
1138+ ) ;
11251139 break ;
11261140 }
11271141 case RootSuspendedWithDelay : {
@@ -1160,12 +1174,20 @@ function finishConcurrentRender(root, exitStatus, lanes) {
11601174 }
11611175
11621176 // Commit the placeholder.
1163- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1177+ commitRoot (
1178+ root ,
1179+ workInProgressRootRecoverableErrors ,
1180+ workInProgressTransitions ,
1181+ ) ;
11641182 break ;
11651183 }
11661184 case RootCompleted: {
11671185 // The work completed. Ready to commit.
1168- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1186+ commitRoot (
1187+ root ,
1188+ workInProgressRootRecoverableErrors ,
1189+ workInProgressTransitions ,
1190+ ) ;
11691191 break ;
11701192 }
11711193 default: {
@@ -1289,7 +1311,11 @@ function performSyncWorkOnRoot(root) {
12891311 const finishedWork: Fiber = (root.current.alternate: any);
12901312 root.finishedWork = finishedWork;
12911313 root.finishedLanes = lanes;
1292- commitRoot(root, workInProgressRootRecoverableErrors);
1314+ commitRoot(
1315+ root,
1316+ workInProgressRootRecoverableErrors,
1317+ workInProgressTransitions,
1318+ );
12931319
12941320 // Before exiting, make sure there's a callback scheduled for the next
12951321 // pending level.
@@ -1971,7 +1997,11 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
19711997 }
19721998}
19731999
1974- function commitRoot ( root : FiberRoot , recoverableErrors : null | Array < mixed > ) {
2000+ function commitRoot (
2001+ root : FiberRoot ,
2002+ recoverableErrors : null | Array < mixed > ,
2003+ transitions : Array < Transition > | null ,
2004+ ) {
19752005 // TODO: This no longer makes any sense. We already wrap the mutation and
19762006 // layout phases. Should be able to remove.
19772007 const previousUpdateLanePriority = getCurrentUpdatePriority ( ) ;
@@ -1980,7 +2010,12 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
19802010 try {
19812011 ReactCurrentBatchConfig . transition = null ;
19822012 setCurrentUpdatePriority ( DiscreteEventPriority ) ;
1983- commitRootImpl ( root , recoverableErrors , previousUpdateLanePriority ) ;
2013+ commitRootImpl (
2014+ root ,
2015+ recoverableErrors ,
2016+ transitions ,
2017+ previousUpdateLanePriority ,
2018+ ) ;
19842019 } finally {
19852020 ReactCurrentBatchConfig . transition = prevTransition ;
19862021 setCurrentUpdatePriority ( previousUpdateLanePriority ) ;
@@ -1992,6 +2027,7 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
19922027function commitRootImpl (
19932028 root : FiberRoot ,
19942029 recoverableErrors : null | Array < mixed > ,
2030+ transitions : Array < Transition > | null ,
19952031 renderPriorityLevel : EventPriority ,
19962032) {
19972033 do {
@@ -2087,6 +2123,13 @@ function commitRootImpl(
20872123 if ( ! rootDoesHavePassiveEffects ) {
20882124 rootDoesHavePassiveEffects = true ;
20892125 pendingPassiveEffectsRemainingLanes = remainingLanes ;
2126+ // workInProgressTransitions might be overwritten, so we want
2127+ // to store it in pendingPassiveTransitions until they get processed
2128+ // We need to pass this through as an argument to commitRoot
2129+ // because workInProgressTransitions might have changed between
2130+ // the previous render and commit if we throttle the commit
2131+ // with setTimeout
2132+ pendingPassiveTransitions = transitions ;
20902133 scheduleCallback ( NormalSchedulerPriority , ( ) => {
20912134 flushPassiveEffects ( ) ;
20922135 // This render triggered passive effects: release the root cache pool
@@ -2407,6 +2450,10 @@ function flushPassiveEffectsImpl() {
24072450 return false ;
24082451 }
24092452
2453+ // Cache and clear the transitions flag
2454+ const transitions = pendingPassiveTransitions ;
2455+ pendingPassiveTransitions = null ;
2456+
24102457 const root = rootWithPendingPassiveEffects ;
24112458 const lanes = pendingPassiveEffectsLanes ;
24122459 rootWithPendingPassiveEffects = null ;
@@ -2436,7 +2483,7 @@ function flushPassiveEffectsImpl() {
24362483 executionContext |= CommitContext ;
24372484
24382485 commitPassiveUnmountEffects ( root . current ) ;
2439- commitPassiveMountEffects ( root , root . current , lanes ) ;
2486+ commitPassiveMountEffects ( root , root . current , lanes , transitions ) ;
24402487
24412488 // TODO: Move to commitPassiveMountEffects
24422489 if ( enableProfilerTimer && enableProfilerCommitHooks ) {
0 commit comments