@@ -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 : {
@@ -1152,20 +1166,33 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1152
1166
// Instead of committing the fallback immediately, wait for more data
1153
1167
// to arrive.
1154
1168
root . timeoutHandle = scheduleTimeout (
1155
- commitRoot . bind ( null , root , workInProgressRootRecoverableErrors ) ,
1169
+ commitRoot . bind (
1170
+ null ,
1171
+ root ,
1172
+ workInProgressRootRecoverableErrors ,
1173
+ workInProgressTransitions ,
1174
+ ) ,
1156
1175
msUntilTimeout ,
1157
1176
) ;
1158
1177
break ;
1159
1178
}
1160
1179
}
1161
1180
1162
1181
// Commit the placeholder.
1163
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1182
+ commitRoot (
1183
+ root ,
1184
+ workInProgressRootRecoverableErrors ,
1185
+ workInProgressTransitions ,
1186
+ ) ;
1164
1187
break ;
1165
1188
}
1166
1189
case RootCompleted: {
1167
1190
// The work completed. Ready to commit.
1168
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1191
+ commitRoot (
1192
+ root ,
1193
+ workInProgressRootRecoverableErrors ,
1194
+ workInProgressTransitions ,
1195
+ ) ;
1169
1196
break ;
1170
1197
}
1171
1198
default: {
@@ -1289,7 +1316,11 @@ function performSyncWorkOnRoot(root) {
1289
1316
const finishedWork: Fiber = (root.current.alternate: any);
1290
1317
root.finishedWork = finishedWork;
1291
1318
root.finishedLanes = lanes;
1292
- commitRoot(root, workInProgressRootRecoverableErrors);
1319
+ commitRoot(
1320
+ root,
1321
+ workInProgressRootRecoverableErrors,
1322
+ workInProgressTransitions,
1323
+ );
1293
1324
1294
1325
// Before exiting, make sure there's a callback scheduled for the next
1295
1326
// pending level.
@@ -1971,7 +2002,11 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1971
2002
}
1972
2003
}
1973
2004
1974
- function commitRoot ( root : FiberRoot , recoverableErrors : null | Array < mixed > ) {
2005
+ function commitRoot (
2006
+ root : FiberRoot ,
2007
+ recoverableErrors : null | Array < mixed > ,
2008
+ transitions : Array < Transition > | null ,
2009
+ ) {
1975
2010
// TODO: This no longer makes any sense. We already wrap the mutation and
1976
2011
// layout phases. Should be able to remove.
1977
2012
const previousUpdateLanePriority = getCurrentUpdatePriority ( ) ;
@@ -1980,7 +2015,12 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1980
2015
try {
1981
2016
ReactCurrentBatchConfig . transition = null ;
1982
2017
setCurrentUpdatePriority ( DiscreteEventPriority ) ;
1983
- commitRootImpl ( root , recoverableErrors , previousUpdateLanePriority ) ;
2018
+ commitRootImpl (
2019
+ root ,
2020
+ recoverableErrors ,
2021
+ transitions ,
2022
+ previousUpdateLanePriority ,
2023
+ ) ;
1984
2024
} finally {
1985
2025
ReactCurrentBatchConfig . transition = prevTransition ;
1986
2026
setCurrentUpdatePriority ( previousUpdateLanePriority ) ;
@@ -1992,6 +2032,7 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1992
2032
function commitRootImpl (
1993
2033
root : FiberRoot ,
1994
2034
recoverableErrors : null | Array < mixed > ,
2035
+ transitions : Array < Transition > | null ,
1995
2036
renderPriorityLevel : EventPriority ,
1996
2037
) {
1997
2038
do {
@@ -2087,6 +2128,13 @@ function commitRootImpl(
2087
2128
if ( ! rootDoesHavePassiveEffects ) {
2088
2129
rootDoesHavePassiveEffects = true ;
2089
2130
pendingPassiveEffectsRemainingLanes = remainingLanes ;
2131
+ // workInProgressTransitions might be overwritten, so we want
2132
+ // to store it in pendingPassiveTransitions until they get processed
2133
+ // We need to pass this through as an argument to commitRoot
2134
+ // because workInProgressTransitions might have changed between
2135
+ // the previous render and commit if we throttle the commit
2136
+ // with setTimeout
2137
+ pendingPassiveTransitions = transitions ;
2090
2138
scheduleCallback ( NormalSchedulerPriority , ( ) => {
2091
2139
flushPassiveEffects ( ) ;
2092
2140
// This render triggered passive effects: release the root cache pool
@@ -2407,6 +2455,10 @@ function flushPassiveEffectsImpl() {
2407
2455
return false ;
2408
2456
}
2409
2457
2458
+ // Cache and clear the transitions flag
2459
+ const transitions = pendingPassiveTransitions ;
2460
+ pendingPassiveTransitions = null ;
2461
+
2410
2462
const root = rootWithPendingPassiveEffects ;
2411
2463
const lanes = pendingPassiveEffectsLanes ;
2412
2464
rootWithPendingPassiveEffects = null ;
@@ -2436,7 +2488,7 @@ function flushPassiveEffectsImpl() {
2436
2488
executionContext |= CommitContext ;
2437
2489
2438
2490
commitPassiveUnmountEffects ( root . current ) ;
2439
- commitPassiveMountEffects ( root , root . current , lanes ) ;
2491
+ commitPassiveMountEffects ( root , root . current , lanes , transitions ) ;
2440
2492
2441
2493
// TODO: Move to commitPassiveMountEffects
2442
2494
if ( enableProfilerTimer && enableProfilerCommitHooks ) {
0 commit comments