@@ -29,7 +29,10 @@ import type {
29
29
import type { HookFlags } from './ReactHookEffectTags' ;
30
30
import type { Cache } from './ReactFiberCacheComponent.old' ;
31
31
import type { RootState } from './ReactFiberRoot.old' ;
32
- import type { Transition } from './ReactFiberTracingMarkerComponent.old' ;
32
+ import type {
33
+ Transition ,
34
+ PendingSuspenseBoundaries ,
35
+ } from './ReactFiberTracingMarkerComponent.old' ;
33
36
34
37
import {
35
38
enableCreateEventHandleAPI ,
@@ -138,6 +141,7 @@ import {
138
141
restorePendingUpdaters ,
139
142
addTransitionStartCallbackToPendingTransition ,
140
143
addTransitionCompleteCallbackToPendingTransition ,
144
+ addMarkerCompleteCallbackToPendingTransition ,
141
145
setIsRunningInsertionEffect ,
142
146
} from './ReactFiberWorkLoop.old' ;
143
147
import {
@@ -1068,6 +1072,7 @@ function reappearLayoutEffectsOnFiber(node: Fiber) {
1068
1072
1069
1073
function commitTransitionProgress (
1070
1074
finishedRoot : FiberRoot ,
1075
+ suspenseBoundaries : Set < PendingSuspenseBoundaries > | null ,
1071
1076
offscreenFiber : Fiber ,
1072
1077
) {
1073
1078
if ( enableTransitionTracing ) {
@@ -1113,35 +1118,42 @@ function commitTransitionProgress(
1113
1118
}
1114
1119
1115
1120
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
+ } ) ;
1121
1128
} ) ;
1122
1129
}
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 ,
1137
1147
} ) ;
1138
- }
1148
+ } ) ;
1139
1149
}
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
+ }
1145
1157
} ) ;
1146
1158
}
1147
1159
}
@@ -2906,11 +2918,13 @@ function commitPassiveMountOnFiber(
2906
2918
}
2907
2919
2908
2920
if ( enableTransitionTracing ) {
2921
+ let suspenseMarkers = null ;
2909
2922
const isFallback = finishedWork . memoizedState ;
2910
2923
const queue = ( finishedWork . updateQueue : any ) ;
2911
2924
const rootMemoizedState = finishedRoot . current . memoizedState ;
2912
2925
2913
2926
if ( queue !== null ) {
2927
+ suspenseMarkers = queue . markerSuspenseBoundaries ;
2914
2928
// We have one instance of the pendingSuspenseBoundaries map.
2915
2929
// We only need one because we update it during the commit phase.
2916
2930
// We instantiate a new Map if we haven't already
@@ -2936,12 +2950,40 @@ function commitPassiveMountOnFiber(
2936
2950
prevTransitions . add ( transition ) ;
2937
2951
} ) ;
2938
2952
}
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
+ }
2939
2975
}
2940
2976
}
2941
2977
2942
- commitTransitionProgress ( finishedRoot , finishedWork ) ;
2978
+ commitTransitionProgress ( finishedRoot , suspenseMarkers , finishedWork ) ;
2943
2979
2944
- finishedWork . updateQueue = null ;
2980
+ if (
2981
+ queue === null ||
2982
+ queue . markerSuspenseBoundaries === null ||
2983
+ queue . markerSuspenseBoundaries . size === 0
2984
+ ) {
2985
+ finishedWork . updateQueue = null ;
2986
+ }
2945
2987
}
2946
2988
2947
2989
break ;
@@ -2967,6 +3009,25 @@ function commitPassiveMountOnFiber(
2967
3009
}
2968
3010
break ;
2969
3011
}
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
+ }
2970
3031
}
2971
3032
}
2972
3033
0 commit comments