@@ -30,7 +30,11 @@ import type {
30
30
import type { HookFlags } from './ReactHookEffectTags' ;
31
31
import type { Cache } from './ReactFiberCacheComponent.old' ;
32
32
import type { RootState } from './ReactFiberRoot.old' ;
33
- import type { Transition } from './ReactFiberTracingMarkerComponent.old' ;
33
+ import type {
34
+ Transition ,
35
+ TracingMarkerInstance ,
36
+ TransitionAbort ,
37
+ } from './ReactFiberTracingMarkerComponent.old' ;
34
38
35
39
import {
36
40
enableCreateEventHandleAPI ,
@@ -146,6 +150,7 @@ import {
146
150
addTransitionProgressCallbackToPendingTransition ,
147
151
addTransitionCompleteCallbackToPendingTransition ,
148
152
addMarkerProgressCallbackToPendingTransition ,
153
+ addMarkerIncompleteCallbackToPendingTransition ,
149
154
addMarkerCompleteCallbackToPendingTransition ,
150
155
setIsRunningInsertionEffect ,
151
156
} from './ReactFiberWorkLoop.old' ;
@@ -1132,6 +1137,91 @@ function commitLayoutEffectOnFiber(
1132
1137
}
1133
1138
}
1134
1139
1140
+ function abortParentMarkerTransitions (
1141
+ deletedFiber : Fiber ,
1142
+ nearestMountedAncestor : Fiber ,
1143
+ abort : TransitionAbort ,
1144
+ ) {
1145
+ let fiber = deletedFiber ;
1146
+ let isInDeletedTree = true ;
1147
+ while ( fiber !== null ) {
1148
+ const instance = deletedFiber . stateNode ;
1149
+ switch ( fiber . tag ) {
1150
+ case TracingMarkerComponent :
1151
+ const transitions = instance . transitions ;
1152
+
1153
+ const markerInstance = fiber . stateNode ;
1154
+ const markerTransitions = markerInstance . transitions ;
1155
+ const abortMarker = Array . from ( transitions ) . some ( transition =>
1156
+ markerTransitions . has ( transition ) ,
1157
+ ) ;
1158
+
1159
+ if ( abortMarker ) {
1160
+ if ( markerInstance . aborts === null ) {
1161
+ markerInstance . aborts = new Set ( ) ;
1162
+ }
1163
+
1164
+ markerInstance . aborts . add ( abort ) ;
1165
+ addMarkerIncompleteCallbackToPendingTransition (
1166
+ fiber . memoizedProps . name ,
1167
+ transitions ,
1168
+ markerInstance . aborts ,
1169
+ ) ;
1170
+
1171
+ // We only want to call onTransitionProgress when the marker hasn't been
1172
+ // deleted
1173
+ if (
1174
+ ! isInDeletedTree &&
1175
+ markerInstance . pendingBoundaries !== null &&
1176
+ markerInstance . pendingBoundaries . has ( instance )
1177
+ ) {
1178
+ markerInstance . pendingBoundaries . delete ( instance ) ;
1179
+
1180
+ addMarkerProgressCallbackToPendingTransition (
1181
+ markerInstance . name ,
1182
+ transitions ,
1183
+ markerInstance . pendingBoundaries ,
1184
+ ) ;
1185
+ }
1186
+ }
1187
+ break ;
1188
+ case HostRoot :
1189
+ const root = fiber . stateNode ;
1190
+ const incompleteTransitions = root . incompleteTransitions ;
1191
+
1192
+ instance . transitions . forEach ( transition => {
1193
+ if ( incompleteTransitions . has ( transition ) ) {
1194
+ const transitionInstance = incompleteTransitions . get ( transition ) ;
1195
+ if ( transitionInstance . aborts === null ) {
1196
+ transitionInstance . aborts = [ ] ;
1197
+ }
1198
+ transitionInstance . aborts . push ( abort ) ;
1199
+
1200
+ if (
1201
+ transitionInstance . pendingBoundaries !== null &&
1202
+ transitionInstance . pendingBoundaries . has ( instance )
1203
+ ) {
1204
+ transitionInstance . pendingBoundaries . delete ( instance ) ;
1205
+ }
1206
+ }
1207
+ } ) ;
1208
+ break ;
1209
+ default :
1210
+ break ;
1211
+ }
1212
+
1213
+ if (
1214
+ nearestMountedAncestor . deletions !== null &&
1215
+ nearestMountedAncestor . deletions . includes ( fiber )
1216
+ ) {
1217
+ isInDeletedTree = false ;
1218
+ fiber = nearestMountedAncestor ;
1219
+ } else {
1220
+ fiber = fiber . return ;
1221
+ }
1222
+ }
1223
+ }
1224
+
1135
1225
function commitTransitionProgress ( offscreenFiber : Fiber ) {
1136
1226
if ( enableTransitionTracing ) {
1137
1227
// This function adds suspense boundaries to the root
@@ -1987,6 +2077,29 @@ function commitDeletionEffectsOnFiber(
1987
2077
const prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden ;
1988
2078
offscreenSubtreeWasHidden =
1989
2079
prevOffscreenSubtreeWasHidden || deletedFiber . memoizedState !== null ;
2080
+
2081
+ if ( enableTransitionTracing ) {
2082
+ // We need to mark this fiber's parents as deleted
2083
+ const instance : OffscreenInstance = deletedFiber . stateNode ;
2084
+ const transitions = instance . transitions ;
2085
+ if ( transitions !== null ) {
2086
+ let name = null ;
2087
+ const parent = deletedFiber . return ;
2088
+ if (
2089
+ parent !== null &&
2090
+ parent . tag === SuspenseComponent &&
2091
+ parent . memoizedProps . unstable_name
2092
+ ) {
2093
+ name = parent . memoizedProps . unstable_name ;
2094
+ }
2095
+
2096
+ abortParentMarkerTransitions ( deletedFiber , nearestMountedAncestor , {
2097
+ reason : 'suspense' ,
2098
+ name,
2099
+ } ) ;
2100
+ }
2101
+ }
2102
+
1990
2103
recursivelyTraverseDeletionEffects (
1991
2104
finishedRoot ,
1992
2105
nearestMountedAncestor ,
@@ -2002,6 +2115,30 @@ function commitDeletionEffectsOnFiber(
2002
2115
}
2003
2116
break ;
2004
2117
}
2118
+ case TracingMarkerComponent : {
2119
+ if ( enableTransitionTracing ) {
2120
+ // We need to mark this fiber's parents as deleted
2121
+ const instance : TracingMarkerInstance = deletedFiber . stateNode ;
2122
+ const transitions = instance . transitions ;
2123
+ if ( transitions !== null ) {
2124
+ const abort = {
2125
+ reason : 'marker' ,
2126
+ name : deletedFiber . memoizedProps . name ,
2127
+ } ;
2128
+ abortParentMarkerTransitions (
2129
+ deletedFiber ,
2130
+ nearestMountedAncestor ,
2131
+ abort ,
2132
+ ) ;
2133
+ }
2134
+ }
2135
+ recursivelyTraverseDeletionEffects (
2136
+ finishedRoot ,
2137
+ nearestMountedAncestor ,
2138
+ deletedFiber ,
2139
+ ) ;
2140
+ return ;
2141
+ }
2005
2142
default : {
2006
2143
recursivelyTraverseDeletionEffects (
2007
2144
finishedRoot ,
@@ -2987,6 +3124,11 @@ function commitOffscreenPassiveMountEffects(
2987
3124
}
2988
3125
2989
3126
commitTransitionProgress ( finishedWork ) ;
3127
+
3128
+ if ( ! isHidden ) {
3129
+ instance . transitions = null ;
3130
+ instance . pendingMarkers = null ;
3131
+ }
2990
3132
}
2991
3133
}
2992
3134
@@ -3023,14 +3165,16 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
3023
3165
( instance . pendingBoundaries === null ||
3024
3166
instance . pendingBoundaries . size === 0 )
3025
3167
) {
3026
- instance . transitions . forEach ( transition => {
3168
+ if ( instance . aborts === null ) {
3027
3169
addMarkerCompleteCallbackToPendingTransition (
3028
3170
finishedWork . memoizedProps . name ,
3029
3171
instance . transitions ,
3030
3172
) ;
3031
- } ) ;
3173
+ }
3032
3174
instance . transitions = null ;
3033
3175
instance . pendingBoundaries = null ;
3176
+ instance . aborts = null ;
3177
+ instance . name = null ;
3034
3178
}
3035
3179
}
3036
3180
@@ -3146,7 +3290,9 @@ function commitPassiveMountOnFiber(
3146
3290
incompleteTransitions . forEach ( ( markerInstance , transition ) => {
3147
3291
const pendingBoundaries = markerInstance . pendingBoundaries ;
3148
3292
if ( pendingBoundaries === null || pendingBoundaries . size === 0 ) {
3149
- addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3293
+ if ( markerInstance . aborts === null ) {
3294
+ addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3295
+ }
3150
3296
incompleteTransitions . delete ( transition ) ;
3151
3297
}
3152
3298
} ) ;
0 commit comments