@@ -30,7 +30,11 @@ import type {
3030import type { HookFlags } from './ReactHookEffectTags' ;
3131import type { Cache } from './ReactFiberCacheComponent.old' ;
3232import 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' ;
3438
3539import {
3640 enableCreateEventHandleAPI ,
@@ -146,6 +150,7 @@ import {
146150 addTransitionProgressCallbackToPendingTransition ,
147151 addTransitionCompleteCallbackToPendingTransition ,
148152 addMarkerProgressCallbackToPendingTransition ,
153+ addMarkerIncompleteCallbackToPendingTransition ,
149154 addMarkerCompleteCallbackToPendingTransition ,
150155 setIsRunningInsertionEffect ,
151156} from './ReactFiberWorkLoop.old' ;
@@ -1132,6 +1137,91 @@ function commitLayoutEffectOnFiber(
11321137 }
11331138}
11341139
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+
11351225function commitTransitionProgress ( offscreenFiber : Fiber ) {
11361226 if ( enableTransitionTracing ) {
11371227 // This function adds suspense boundaries to the root
@@ -1987,6 +2077,29 @@ function commitDeletionEffectsOnFiber(
19872077 const prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden ;
19882078 offscreenSubtreeWasHidden =
19892079 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+
19902103 recursivelyTraverseDeletionEffects (
19912104 finishedRoot ,
19922105 nearestMountedAncestor ,
@@ -2002,6 +2115,30 @@ function commitDeletionEffectsOnFiber(
20022115 }
20032116 break ;
20042117 }
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+ }
20052142 default : {
20062143 recursivelyTraverseDeletionEffects (
20072144 finishedRoot ,
@@ -2987,6 +3124,11 @@ function commitOffscreenPassiveMountEffects(
29873124 }
29883125
29893126 commitTransitionProgress ( finishedWork ) ;
3127+
3128+ if ( ! isHidden ) {
3129+ instance . transitions = null ;
3130+ instance . pendingMarkers = null ;
3131+ }
29903132 }
29913133}
29923134
@@ -3023,14 +3165,16 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
30233165 ( instance . pendingBoundaries === null ||
30243166 instance . pendingBoundaries . size === 0 )
30253167 ) {
3026- instance . transitions . forEach ( transition => {
3168+ if ( instance . aborts === null ) {
30273169 addMarkerCompleteCallbackToPendingTransition (
30283170 finishedWork . memoizedProps . name ,
30293171 instance . transitions ,
30303172 ) ;
3031- } ) ;
3173+ }
30323174 instance . transitions = null ;
30333175 instance . pendingBoundaries = null ;
3176+ instance . aborts = null ;
3177+ instance . name = null ;
30343178 }
30353179}
30363180
@@ -3146,7 +3290,9 @@ function commitPassiveMountOnFiber(
31463290 incompleteTransitions . forEach ( ( markerInstance , transition ) => {
31473291 const pendingBoundaries = markerInstance . pendingBoundaries ;
31483292 if ( pendingBoundaries === null || pendingBoundaries . size === 0 ) {
3149- addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3293+ if ( markerInstance . aborts === null ) {
3294+ addTransitionCompleteCallbackToPendingTransition ( transition ) ;
3295+ }
31503296 incompleteTransitions . delete ( transition ) ;
31513297 }
31523298 } ) ;
0 commit comments