@@ -29,7 +29,10 @@ import type {
2929import type { HookFlags } from './ReactHookEffectTags' ;
3030import type { Cache } from './ReactFiberCacheComponent.old' ;
3131import type { RootState } from './ReactFiberRoot.old' ;
32- import type { Transition } from './ReactFiberTracingMarkerComponent.old' ;
32+ import type {
33+ Transition ,
34+ PendingSuspenseBoundaries ,
35+ } from './ReactFiberTracingMarkerComponent.old' ;
3336
3437import {
3538 enableCreateEventHandleAPI ,
@@ -138,6 +141,7 @@ import {
138141 restorePendingUpdaters ,
139142 addTransitionStartCallbackToPendingTransition ,
140143 addTransitionCompleteCallbackToPendingTransition ,
144+ addMarkerCompleteCallbackToPendingTransition ,
141145 setIsRunningInsertionEffect ,
142146} from './ReactFiberWorkLoop.old' ;
143147import {
@@ -1068,6 +1072,7 @@ function reappearLayoutEffectsOnFiber(node: Fiber) {
10681072
10691073function commitTransitionProgress (
10701074 finishedRoot : FiberRoot ,
1075+ suspenseBoundaries : Set < PendingSuspenseBoundaries > | null ,
10711076 offscreenFiber : Fiber ,
10721077) {
10731078 if ( enableTransitionTracing ) {
@@ -1113,35 +1118,42 @@ function commitTransitionProgress(
11131118 }
11141119
11151120 if ( rootPendingBoundaries !== null ) {
1116- if ( previousFiber === null ) {
1117- // Initial mount
1118- if ( isHidden ) {
1119- rootPendingBoundaries . set ( offscreenInstance , {
1120- name,
1121+ // Initial mount or hide
1122+ if ( ! wasHidden && isHidden ) {
1123+ if ( suspenseBoundaries !== null ) {
1124+ suspenseBoundaries . forEach ( pendingBoundaries => {
1125+ pendingBoundaries . set ( offscreenInstance , {
1126+ name,
1127+ } ) ;
11211128 } ) ;
11221129 }
1123- } else {
1124- if ( wasHidden && ! isHidden ) {
1125- // The suspense boundary went from hidden to visible. Remove
1126- // the boundary from the pending suspense boundaries set
1127- // if it's there
1128- if ( rootPendingBoundaries . has ( offscreenInstance ) ) {
1129- rootPendingBoundaries . delete ( offscreenInstance ) ;
1130-
1131- if ( rootPendingBoundaries . size === 0 && rootTransitions !== null ) {
1132- rootTransitions . forEach ( transition => {
1133- addTransitionCompleteCallbackToPendingTransition ( {
1134- transitionName : transition . name ,
1135- startTime : transition . startTime ,
1136- } ) ;
1130+ // The suspense boundaries was just hidden. Add the boundary
1131+ // to the pending boundary set if it's there
1132+ rootPendingBoundaries . set ( offscreenInstance , {
1133+ name,
1134+ } ) ;
1135+ } else if ( wasHidden && ! isHidden ) {
1136+ // The suspense boundary went from hidden to visible. Remove
1137+ // the boundary from the pending suspense boundaries set
1138+ // if it's there
1139+ if ( rootPendingBoundaries . has ( offscreenInstance ) ) {
1140+ rootPendingBoundaries . delete ( offscreenInstance ) ;
1141+
1142+ if ( rootPendingBoundaries . size === 0 && rootTransitions !== null ) {
1143+ rootTransitions . forEach ( transition => {
1144+ addTransitionCompleteCallbackToPendingTransition ( {
1145+ transitionName : transition . name ,
1146+ startTime : transition . startTime ,
11371147 } ) ;
1138- }
1148+ } ) ;
11391149 }
1140- } else if ( ! wasHidden && isHidden ) {
1141- // The suspense boundaries was just hidden. Add the boundary
1142- // to the pending boundary set if it's there
1143- rootPendingBoundaries . set ( offscreenInstance , {
1144- name,
1150+ }
1151+
1152+ if ( suspenseBoundaries !== null ) {
1153+ suspenseBoundaries . forEach ( pendingBoundaries => {
1154+ if ( pendingBoundaries . has ( offscreenInstance ) ) {
1155+ pendingBoundaries . delete ( offscreenInstance ) ;
1156+ }
11451157 } ) ;
11461158 }
11471159 }
@@ -2906,11 +2918,13 @@ function commitPassiveMountOnFiber(
29062918 }
29072919
29082920 if ( enableTransitionTracing ) {
2921+ let suspenseMarkers = null ;
29092922 const isFallback = finishedWork . memoizedState ;
29102923 const queue = ( finishedWork . updateQueue : any ) ;
29112924 const rootMemoizedState = finishedRoot . current . memoizedState ;
29122925
29132926 if ( queue !== null ) {
2927+ suspenseMarkers = queue . markerSuspenseBoundaries ;
29142928 // We have one instance of the pendingSuspenseBoundaries map.
29152929 // We only need one because we update it during the commit phase.
29162930 // We instantiate a new Map if we haven't already
@@ -2936,12 +2950,40 @@ function commitPassiveMountOnFiber(
29362950 prevTransitions . add ( transition ) ;
29372951 } ) ;
29382952 }
2953+ const tracingMarkers = queue . tracingMarkers ;
2954+
2955+ if ( tracingMarkers !== null ) {
2956+ if ( suspenseMarkers === null ) {
2957+ queue . markerSuspenseBoundaries = suspenseMarkers = new Set ( ) ;
2958+ }
2959+
2960+ tracingMarkers . forEach ( marker => {
2961+ const markerTransitions = marker . memoizedState . transitions ;
2962+
2963+ // There should only be a few tracing marker transitions because
2964+ // they should be only associated with the transition that
2965+ // caused them
2966+ markerTransitions . forEach ( transition => {
2967+ if ( finishedWork . memoizedState . transitions . has ( transition ) ) {
2968+ queue . markerSuspenseBoundaries . add (
2969+ marker . memoizedState . pendingSuspenseBoundaries ,
2970+ ) ;
2971+ }
2972+ } ) ;
2973+ } ) ;
2974+ }
29392975 }
29402976 }
29412977
2942- commitTransitionProgress ( finishedRoot , finishedWork ) ;
2978+ commitTransitionProgress ( finishedRoot , suspenseMarkers , finishedWork ) ;
29432979
2944- finishedWork . updateQueue = null ;
2980+ if (
2981+ queue === null ||
2982+ queue . markerSuspenseBoundaries === null ||
2983+ queue . markerSuspenseBoundaries . size === 0
2984+ ) {
2985+ finishedWork . updateQueue = null ;
2986+ }
29452987 }
29462988
29472989 break ;
@@ -2967,6 +3009,25 @@ function commitPassiveMountOnFiber(
29673009 }
29683010 break ;
29693011 }
3012+ case TracingMarkerComponent : {
3013+ if ( enableTransitionTracing ) {
3014+ // Get the transitions that were initiatized during the render
3015+ // and add a start transition callback for each of them
3016+ const state = finishedWork . memoizedState ;
3017+ if ( state !== null && state . pendingSuspenseBoundaries . size === 0 ) {
3018+ state . transitions . forEach ( transition => {
3019+ addMarkerCompleteCallbackToPendingTransition ( {
3020+ transitionName : transition . name ,
3021+ startTime : transition . startTime ,
3022+ markerName : finishedWork . memoizedProps . name ,
3023+ } ) ;
3024+ } ) ;
3025+
3026+ finishedWork . memoizedState = null ;
3027+ }
3028+ }
3029+ break ;
3030+ }
29703031 }
29713032}
29723033
0 commit comments