@@ -391,6 +391,7 @@ let rootWithPendingPassiveEffects: FiberRoot | null = null;
391
391
let pendingPassiveEffectsLanes: Lanes = NoLanes;
392
392
let pendingPassiveProfilerEffects: Array< Fiber > = [];
393
393
let pendingPassiveEffectsRemainingLanes: Lanes = NoLanes;
394
+ let pendingPassiveTransitions: Array< Transition > | null = null;
394
395
395
396
// Use these to prevent an infinite loop of nested updates
396
397
const NESTED_UPDATE_LIMIT = 50;
@@ -1074,7 +1075,11 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1074
1075
case RootErrored : {
1075
1076
// We should have already attempted to retry this tree. If we reached
1076
1077
// this point, it errored again. Commit it.
1077
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1078
+ commitRoot (
1079
+ root ,
1080
+ workInProgressRootRecoverableErrors ,
1081
+ workInProgressTransitions ,
1082
+ ) ;
1078
1083
break ;
1079
1084
}
1080
1085
case RootSuspended : {
@@ -1114,14 +1119,23 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1114
1119
// lower priority work to do. Instead of committing the fallback
1115
1120
// immediately, wait for more data to arrive.
1116
1121
root . timeoutHandle = scheduleTimeout (
1117
- commitRoot . bind ( null , root , workInProgressRootRecoverableErrors ) ,
1122
+ commitRoot . bind (
1123
+ null ,
1124
+ root ,
1125
+ workInProgressRootRecoverableErrors ,
1126
+ workInProgressTransitions ,
1127
+ ) ,
1118
1128
msUntilTimeout ,
1119
1129
) ;
1120
1130
break ;
1121
1131
}
1122
1132
}
1123
1133
// The work expired. Commit immediately.
1124
- commitRoot ( root , workInProgressRootRecoverableErrors) ;
1134
+ commitRoot (
1135
+ root ,
1136
+ workInProgressRootRecoverableErrors ,
1137
+ workInProgressTransitions ,
1138
+ ) ;
1125
1139
break ;
1126
1140
}
1127
1141
case RootSuspendedWithDelay : {
@@ -1160,12 +1174,20 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1160
1174
}
1161
1175
1162
1176
// Commit the placeholder.
1163
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1177
+ commitRoot (
1178
+ root ,
1179
+ workInProgressRootRecoverableErrors ,
1180
+ workInProgressTransitions ,
1181
+ ) ;
1164
1182
break ;
1165
1183
}
1166
1184
case RootCompleted: {
1167
1185
// The work completed. Ready to commit.
1168
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1186
+ commitRoot (
1187
+ root ,
1188
+ workInProgressRootRecoverableErrors ,
1189
+ workInProgressTransitions ,
1190
+ ) ;
1169
1191
break ;
1170
1192
}
1171
1193
default: {
@@ -1289,7 +1311,11 @@ function performSyncWorkOnRoot(root) {
1289
1311
const finishedWork: Fiber = (root.current.alternate: any);
1290
1312
root.finishedWork = finishedWork;
1291
1313
root.finishedLanes = lanes;
1292
- commitRoot(root, workInProgressRootRecoverableErrors);
1314
+ commitRoot(
1315
+ root,
1316
+ workInProgressRootRecoverableErrors,
1317
+ workInProgressTransitions,
1318
+ );
1293
1319
1294
1320
// Before exiting, make sure there's a callback scheduled for the next
1295
1321
// pending level.
@@ -1971,7 +1997,11 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1971
1997
}
1972
1998
}
1973
1999
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
+ ) {
1975
2005
// TODO: This no longer makes any sense. We already wrap the mutation and
1976
2006
// layout phases. Should be able to remove.
1977
2007
const previousUpdateLanePriority = getCurrentUpdatePriority ( ) ;
@@ -1980,7 +2010,12 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1980
2010
try {
1981
2011
ReactCurrentBatchConfig . transition = null ;
1982
2012
setCurrentUpdatePriority ( DiscreteEventPriority ) ;
1983
- commitRootImpl ( root , recoverableErrors , previousUpdateLanePriority ) ;
2013
+ commitRootImpl (
2014
+ root ,
2015
+ recoverableErrors ,
2016
+ transitions ,
2017
+ previousUpdateLanePriority ,
2018
+ ) ;
1984
2019
} finally {
1985
2020
ReactCurrentBatchConfig . transition = prevTransition ;
1986
2021
setCurrentUpdatePriority ( previousUpdateLanePriority ) ;
@@ -1992,6 +2027,7 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1992
2027
function commitRootImpl (
1993
2028
root : FiberRoot ,
1994
2029
recoverableErrors : null | Array < mixed > ,
2030
+ transitions : Array < Transition > | null ,
1995
2031
renderPriorityLevel : EventPriority ,
1996
2032
) {
1997
2033
do {
@@ -2087,6 +2123,13 @@ function commitRootImpl(
2087
2123
if ( ! rootDoesHavePassiveEffects ) {
2088
2124
rootDoesHavePassiveEffects = true ;
2089
2125
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 ;
2090
2133
scheduleCallback ( NormalSchedulerPriority , ( ) => {
2091
2134
flushPassiveEffects ( ) ;
2092
2135
// This render triggered passive effects: release the root cache pool
@@ -2407,6 +2450,10 @@ function flushPassiveEffectsImpl() {
2407
2450
return false ;
2408
2451
}
2409
2452
2453
+ // Cache and clear the transitions flag
2454
+ const transitions = pendingPassiveTransitions ;
2455
+ pendingPassiveTransitions = null ;
2456
+
2410
2457
const root = rootWithPendingPassiveEffects ;
2411
2458
const lanes = pendingPassiveEffectsLanes ;
2412
2459
rootWithPendingPassiveEffects = null ;
@@ -2436,7 +2483,7 @@ function flushPassiveEffectsImpl() {
2436
2483
executionContext |= CommitContext ;
2437
2484
2438
2485
commitPassiveUnmountEffects ( root . current ) ;
2439
- commitPassiveMountEffects ( root , root . current , lanes ) ;
2486
+ commitPassiveMountEffects ( root , root . current , lanes , transitions ) ;
2440
2487
2441
2488
// TODO: Move to commitPassiveMountEffects
2442
2489
if ( enableProfilerTimer && enableProfilerCommitHooks ) {
0 commit comments