@@ -29,7 +29,10 @@ import type {
2929import type { HookFlags } from './ReactHookEffectTags' ;
3030import type { Cache } from './ReactFiberCacheComponent.new' ;
3131import type { RootState } from './ReactFiberRoot.new' ;
32- import type { Transition } from './ReactFiberTracingMarkerComponent.new' ;
32+ import type {
33+ Transition ,
34+ TracingMarkerState ,
35+ } from './ReactFiberTracingMarkerComponent.new' ;
3336
3437import {
3538 enableCreateEventHandleAPI ,
@@ -139,6 +142,7 @@ import {
139142 restorePendingUpdaters ,
140143 addTransitionStartCallbackToPendingTransition ,
141144 addTransitionCompleteCallbackToPendingTransition ,
145+ addMarkerCompleteCallbackToPendingTransition ,
142146 setIsRunningInsertionEffect ,
143147} from './ReactFiberWorkLoop.new' ;
144148import {
@@ -1073,6 +1077,7 @@ function reappearLayoutEffectsOnFiber(node: Fiber) {
10731077
10741078function commitTransitionProgress (
10751079 finishedRoot : FiberRoot ,
1080+ suspenseBoundaries : Array < PendingSuspenseBoundaries > | null ,
10761081 offscreenFiber : Fiber ,
10771082) {
10781083 if ( enableTransitionTracing ) {
@@ -1118,35 +1123,42 @@ function commitTransitionProgress(
11181123 }
11191124
11201125 if ( rootPendingBoundaries !== null ) {
1121- if ( previousFiber === null ) {
1122- // Initial mount
1123- if ( isHidden ) {
1124- rootPendingBoundaries . set ( offscreenInstance , {
1125- name,
1126+ // Initial mount or hide
1127+ if ( ! wasHidden && isHidden ) {
1128+ if ( suspenseBoundaries !== null ) {
1129+ suspenseBoundaries . forEach ( pendingBoundaries => {
1130+ pendingBoundaries . set ( offscreenInstance , {
1131+ name,
1132+ } ) ;
11261133 } ) ;
11271134 }
1128- } else {
1129- if ( wasHidden && ! isHidden ) {
1130- // The suspense boundary went from hidden to visible. Remove
1131- // the boundary from the pending suspense boundaries set
1132- // if it's there
1133- if ( rootPendingBoundaries . has ( offscreenInstance ) ) {
1134- rootPendingBoundaries . delete ( offscreenInstance ) ;
1135-
1136- if ( rootPendingBoundaries . size === 0 && rootTransitions !== null ) {
1137- rootTransitions . forEach ( transition => {
1138- addTransitionCompleteCallbackToPendingTransition ( {
1139- transitionName : transition . name ,
1140- startTime : transition . startTime ,
1141- } ) ;
1135+ // The suspense boundaries was just hidden. Add the boundary
1136+ // to the pending boundary set if it's there
1137+ rootPendingBoundaries . set ( offscreenInstance , {
1138+ name,
1139+ } ) ;
1140+ } else if ( wasHidden && ! isHidden ) {
1141+ // The suspense boundary went from hidden to visible. Remove
1142+ // the boundary from the pending suspense boundaries set
1143+ // if it's there
1144+ if ( rootPendingBoundaries . has ( offscreenInstance ) ) {
1145+ rootPendingBoundaries . delete ( offscreenInstance ) ;
1146+
1147+ if ( rootPendingBoundaries . size === 0 && rootTransitions !== null ) {
1148+ rootTransitions . forEach ( transition => {
1149+ addTransitionCompleteCallbackToPendingTransition ( {
1150+ transitionName : transition . name ,
1151+ startTime : transition . startTime ,
11421152 } ) ;
1143- }
1153+ } ) ;
11441154 }
1145- } else if ( ! wasHidden && isHidden ) {
1146- // The suspense boundaries was just hidden. Add the boundary
1147- // to the pending boundary set if it's there
1148- rootPendingBoundaries . set ( offscreenInstance , {
1149- name,
1155+ }
1156+
1157+ if ( suspenseBoundaries !== null ) {
1158+ suspenseBoundaries . forEach ( pendingBoundaries => {
1159+ if ( pendingBoundaries . has ( offscreenInstance ) ) {
1160+ pendingBoundaries . delete ( offscreenInstance ) ;
1161+ }
11501162 } ) ;
11511163 }
11521164 }
@@ -2914,11 +2926,13 @@ function commitPassiveMountOnFiber(
29142926 }
29152927
29162928 if ( enableTransitionTracing ) {
2929+ let suspenseMarkers = null ;
29172930 const isFallback = finishedWork . memoizedState ;
29182931 const queue = ( finishedWork . updateQueue : any ) ;
29192932 const rootMemoizedState = finishedRoot . current . memoizedState ;
29202933
29212934 if ( queue !== null ) {
2935+ suspenseMarkers = queue . markerSuspenseBoundaries ;
29222936 // We have one instance of the pendingSuspenseBoundaries map.
29232937 // We only need one because we update it during the commit phase.
29242938 // We instantiate a new Map if we haven't already
@@ -2944,12 +2958,39 @@ function commitPassiveMountOnFiber(
29442958 prevTransitions . add ( transition ) ;
29452959 } ) ;
29462960 }
2961+ const tracingMarkers = queue . tracingMarkers ;
2962+
2963+ if ( tracingMarkers !== null ) {
2964+ if ( suspenseMarkers === null ) {
2965+ queue . markerSuspenseBoundaries = suspenseMarkers = new Set ( ) ;
2966+ }
2967+ tracingMarkers . forEach ( marker => {
2968+ const markerTransitions = marker . memoizedState . transitions ;
2969+
2970+ // There should only be a few tracing marker transitions because
2971+ // they should be only associated with the transition that
2972+ // caused them
2973+ markerTransitions . forEach ( transition => {
2974+ if ( finishedWork . memoizedState . transitions . has ( transition ) ) {
2975+ suspenseMarkers . add (
2976+ marker . memoizedState . pendingSuspenseBoundaries ,
2977+ ) ;
2978+ }
2979+ } ) ;
2980+ } ) ;
2981+ }
29472982 }
29482983 }
29492984
2950- commitTransitionProgress ( finishedRoot , finishedWork ) ;
2985+ commitTransitionProgress ( finishedRoot , suspenseMarkers , finishedWork ) ;
29512986
2952- finishedWork . updateQueue = null ;
2987+ if (
2988+ queue === null ||
2989+ queue . markerSuspenseBoundaries === null ||
2990+ queue . markerSuspenseBoundaries . size === 0
2991+ ) {
2992+ finishedWork . updateQueue = null ;
2993+ }
29532994 }
29542995
29552996 break ;
@@ -2975,6 +3016,25 @@ function commitPassiveMountOnFiber(
29753016 }
29763017 break ;
29773018 }
3019+ case TracingMarkerComponent : {
3020+ if ( enableTransitionTracing ) {
3021+ // Get the transitions that were initiatized during the render
3022+ // and add a start transition callback for each of them
3023+ const state = finishedWork . memoizedState ;
3024+ if ( state !== null && state . pendingSuspenseBoundaries . size === 0 ) {
3025+ state . transitions . forEach ( transition => {
3026+ addMarkerCompleteCallbackToPendingTransition ( {
3027+ transitionName : transition . name ,
3028+ startTime : transition . startTime ,
3029+ markerName : finishedWork . memoizedProps . name ,
3030+ } ) ;
3031+ } ) ;
3032+
3033+ finishedWork . memoizedState = null ;
3034+ }
3035+ }
3036+ break ;
3037+ }
29783038 }
29793039}
29803040
0 commit comments