@@ -392,6 +392,7 @@ let rootWithPendingPassiveEffects: FiberRoot | null = null;
392
392
let pendingPassiveEffectsLanes: Lanes = NoLanes;
393
393
let pendingPassiveProfilerEffects: Array< Fiber > = [];
394
394
let pendingPassiveEffectsRemainingLanes: Lanes = NoLanes;
395
+ let pendingPassiveTransitions: Array< Transition > | null = null;
395
396
396
397
// Use these to prevent an infinite loop of nested updates
397
398
const NESTED_UPDATE_LIMIT = 50;
@@ -1075,7 +1076,11 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1075
1076
case RootErrored : {
1076
1077
// We should have already attempted to retry this tree. If we reached
1077
1078
// this point, it errored again. Commit it.
1078
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1079
+ commitRoot (
1080
+ root ,
1081
+ workInProgressRootRecoverableErrors ,
1082
+ workInProgressTransitions ,
1083
+ ) ;
1079
1084
break ;
1080
1085
}
1081
1086
case RootSuspended : {
@@ -1115,14 +1120,23 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1115
1120
// lower priority work to do. Instead of committing the fallback
1116
1121
// immediately, wait for more data to arrive.
1117
1122
root . timeoutHandle = scheduleTimeout (
1118
- commitRoot . bind ( null , root , workInProgressRootRecoverableErrors ) ,
1123
+ commitRoot . bind (
1124
+ null ,
1125
+ root ,
1126
+ workInProgressRootRecoverableErrors ,
1127
+ workInProgressTransitions ,
1128
+ ) ,
1119
1129
msUntilTimeout ,
1120
1130
) ;
1121
1131
break ;
1122
1132
}
1123
1133
}
1124
1134
// The work expired. Commit immediately.
1125
- commitRoot ( root , workInProgressRootRecoverableErrors) ;
1135
+ commitRoot (
1136
+ root ,
1137
+ workInProgressRootRecoverableErrors ,
1138
+ workInProgressTransitions ,
1139
+ ) ;
1126
1140
break ;
1127
1141
}
1128
1142
case RootSuspendedWithDelay : {
@@ -1153,20 +1167,33 @@ function finishConcurrentRender(root, exitStatus, lanes) {
1153
1167
// Instead of committing the fallback immediately, wait for more data
1154
1168
// to arrive.
1155
1169
root . timeoutHandle = scheduleTimeout (
1156
- commitRoot . bind ( null , root , workInProgressRootRecoverableErrors ) ,
1170
+ commitRoot . bind (
1171
+ null ,
1172
+ root ,
1173
+ workInProgressRootRecoverableErrors ,
1174
+ workInProgressTransitions ,
1175
+ ) ,
1157
1176
msUntilTimeout ,
1158
1177
) ;
1159
1178
break ;
1160
1179
}
1161
1180
}
1162
1181
1163
1182
// Commit the placeholder.
1164
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1183
+ commitRoot (
1184
+ root ,
1185
+ workInProgressRootRecoverableErrors ,
1186
+ workInProgressTransitions ,
1187
+ ) ;
1165
1188
break ;
1166
1189
}
1167
1190
case RootCompleted: {
1168
1191
// The work completed. Ready to commit.
1169
- commitRoot ( root , workInProgressRootRecoverableErrors ) ;
1192
+ commitRoot (
1193
+ root ,
1194
+ workInProgressRootRecoverableErrors ,
1195
+ workInProgressTransitions ,
1196
+ ) ;
1170
1197
break ;
1171
1198
}
1172
1199
default: {
@@ -1290,7 +1317,11 @@ function performSyncWorkOnRoot(root) {
1290
1317
const finishedWork: Fiber = (root.current.alternate: any);
1291
1318
root.finishedWork = finishedWork;
1292
1319
root.finishedLanes = lanes;
1293
- commitRoot(root, workInProgressRootRecoverableErrors);
1320
+ commitRoot(
1321
+ root,
1322
+ workInProgressRootRecoverableErrors,
1323
+ workInProgressTransitions,
1324
+ );
1294
1325
1295
1326
// Before exiting, make sure there's a callback scheduled for the next
1296
1327
// pending level.
@@ -1972,7 +2003,11 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1972
2003
}
1973
2004
}
1974
2005
1975
- function commitRoot ( root : FiberRoot , recoverableErrors : null | Array < mixed > ) {
2006
+ function commitRoot (
2007
+ root : FiberRoot ,
2008
+ recoverableErrors : null | Array < mixed > ,
2009
+ transitions : Array < Transition > | null ,
2010
+ ) {
1976
2011
// TODO: This no longer makes any sense. We already wrap the mutation and
1977
2012
// layout phases. Should be able to remove.
1978
2013
const previousUpdateLanePriority = getCurrentUpdatePriority ( ) ;
@@ -1981,7 +2016,12 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1981
2016
try {
1982
2017
ReactCurrentBatchConfig . transition = null ;
1983
2018
setCurrentUpdatePriority ( DiscreteEventPriority ) ;
1984
- commitRootImpl ( root , recoverableErrors , previousUpdateLanePriority ) ;
2019
+ commitRootImpl (
2020
+ root ,
2021
+ recoverableErrors ,
2022
+ transitions ,
2023
+ previousUpdateLanePriority ,
2024
+ ) ;
1985
2025
} finally {
1986
2026
ReactCurrentBatchConfig . transition = prevTransition ;
1987
2027
setCurrentUpdatePriority ( previousUpdateLanePriority ) ;
@@ -1993,6 +2033,7 @@ function commitRoot(root: FiberRoot, recoverableErrors: null | Array<mixed>) {
1993
2033
function commitRootImpl (
1994
2034
root : FiberRoot ,
1995
2035
recoverableErrors : null | Array < mixed > ,
2036
+ transitions : Array < Transition > | null ,
1996
2037
renderPriorityLevel : EventPriority ,
1997
2038
) {
1998
2039
do {
@@ -2088,6 +2129,13 @@ function commitRootImpl(
2088
2129
if ( ! rootDoesHavePassiveEffects ) {
2089
2130
rootDoesHavePassiveEffects = true ;
2090
2131
pendingPassiveEffectsRemainingLanes = remainingLanes ;
2132
+ // workInProgressTransitions might be overwritten, so we want
2133
+ // to store it in pendingPassiveTransitions until they get processed
2134
+ // We need to pass this through as an argument to commitRoot
2135
+ // because workInProgressTransitions might have changed between
2136
+ // the previous render and commit if we throttle the commit
2137
+ // with setTimeout
2138
+ pendingPassiveTransitions = transitions ;
2091
2139
scheduleCallback ( NormalSchedulerPriority , ( ) => {
2092
2140
flushPassiveEffects ( ) ;
2093
2141
// This render triggered passive effects: release the root cache pool
@@ -2408,6 +2456,10 @@ function flushPassiveEffectsImpl() {
2408
2456
return false ;
2409
2457
}
2410
2458
2459
+ // Cache and clear the transitions flag
2460
+ const transitions = pendingPassiveTransitions ;
2461
+ pendingPassiveTransitions = null ;
2462
+
2411
2463
const root = rootWithPendingPassiveEffects ;
2412
2464
const lanes = pendingPassiveEffectsLanes ;
2413
2465
rootWithPendingPassiveEffects = null ;
@@ -2437,7 +2489,7 @@ function flushPassiveEffectsImpl() {
2437
2489
executionContext |= CommitContext ;
2438
2490
2439
2491
commitPassiveUnmountEffects ( root . current ) ;
2440
- commitPassiveMountEffects ( root , root . current , lanes ) ;
2492
+ commitPassiveMountEffects ( root , root . current , lanes , transitions ) ;
2441
2493
2442
2494
// TODO: Move to commitPassiveMountEffects
2443
2495
if ( enableProfilerTimer && enableProfilerCommitHooks ) {
0 commit comments