@@ -30,7 +30,11 @@ import type {
30
30
import type { HookFlags } from './ReactHookEffectTags' ;
31
31
import type { Cache } from './ReactFiberCacheComponent.new' ;
32
32
import type { RootState } from './ReactFiberRoot.new' ;
33
- import type { Transition } from './ReactFiberTracingMarkerComponent.new' ;
33
+ import type {
34
+ Transition ,
35
+ TracingMarkerInstance ,
36
+ TransitionAbort ,
37
+ } from './ReactFiberTracingMarkerComponent.new' ;
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.new' ;
@@ -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,20 @@ 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 markers = instance . pendingMarkers ;
2085
+ if ( markers !== null ) {
2086
+ markers . forEach ( marker => {
2087
+ if ( marker . pendingBoundaries . has ( instance ) ) {
2088
+ marker . pendingBoundaries . delete ( instance ) ;
2089
+ }
2090
+ } ) ;
2091
+ }
2092
+ }
2093
+
1990
2094
recursivelyTraverseDeletionEffects (
1991
2095
finishedRoot ,
1992
2096
nearestMountedAncestor ,
@@ -2002,6 +2106,30 @@ function commitDeletionEffectsOnFiber(
2002
2106
}
2003
2107
break ;
2004
2108
}
2109
+ case TracingMarkerComponent : {
2110
+ if ( enableTransitionTracing ) {
2111
+ // We need to mark this fiber's parents as deleted
2112
+ const instance : TracingMarkerInstance = deletedFiber . stateNode ;
2113
+ const transitions = instance . transitions ;
2114
+ if ( transitions !== null ) {
2115
+ const abort = {
2116
+ reason : 'marker' ,
2117
+ name : deletedFiber . memoizedProps . name ,
2118
+ } ;
2119
+ abortParentMarkerTransitions (
2120
+ deletedFiber ,
2121
+ nearestMountedAncestor ,
2122
+ abort ,
2123
+ ) ;
2124
+ }
2125
+ }
2126
+ recursivelyTraverseDeletionEffects (
2127
+ finishedRoot ,
2128
+ nearestMountedAncestor ,
2129
+ deletedFiber ,
2130
+ ) ;
2131
+ return ;
2132
+ }
2005
2133
default : {
2006
2134
recursivelyTraverseDeletionEffects (
2007
2135
finishedRoot ,
@@ -2987,6 +3115,11 @@ function commitOffscreenPassiveMountEffects(
2987
3115
}
2988
3116
2989
3117
commitTransitionProgress ( finishedWork ) ;
3118
+
3119
+ if ( ! isHidden ) {
3120
+ instance . transitions = null ;
3121
+ instance . pendingMarkers = null ;
3122
+ }
2990
3123
}
2991
3124
}
2992
3125
@@ -3023,14 +3156,16 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
3023
3156
( instance . pendingBoundaries === null ||
3024
3157
instance . pendingBoundaries . size === 0 )
3025
3158
) {
3026
- instance . transitions . forEach ( transition => {
3159
+ if ( instance . aborts === null ) {
3027
3160
addMarkerCompleteCallbackToPendingTransition (
3028
3161
finishedWork . memoizedProps . name ,
3029
3162
instance . transitions ,
3030
3163
) ;
3031
- } ) ;
3164
+ }
3032
3165
instance . transitions = null ;
3033
3166
instance . pendingBoundaries = null ;
3167
+ instance . aborts = null ;
3168
+ instance . name = null ;
3034
3169
}
3035
3170
}
3036
3171
@@ -3146,7 +3281,9 @@ function commitPassiveMountOnFiber(
3146
3281
incompleteTransitions . forEach ( ( markerInstance , transition ) => {
3147
3282
const pendingBoundaries = markerInstance . pendingBoundaries ;
3148
3283
if ( pendingBoundaries === null || pendingBoundaries . size === 0 ) {
3149
- addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3284
+ if ( markerInstance . aborts === null ) {
3285
+ addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3286
+ }
3150
3287
incompleteTransitions . delete ( transition ) ;
3151
3288
}
3152
3289
} ) ;
0 commit comments