@@ -29,7 +29,10 @@ import type {
29
29
import type { HookFlags } from './ReactHookEffectTags' ;
30
30
import type { Cache } from './ReactFiberCacheComponent.new' ;
31
31
import type { RootState } from './ReactFiberRoot.new' ;
32
- import type { Transition } from './ReactFiberTracingMarkerComponent.new' ;
32
+ import type {
33
+ Transition ,
34
+ TracingMarkerState ,
35
+ } from './ReactFiberTracingMarkerComponent.new' ;
33
36
34
37
import {
35
38
enableCreateEventHandleAPI ,
@@ -139,6 +142,7 @@ import {
139
142
restorePendingUpdaters ,
140
143
addTransitionStartCallbackToPendingTransition ,
141
144
addTransitionCompleteCallbackToPendingTransition ,
145
+ addMarkerCompleteCallbackToPendingTransition ,
142
146
setIsRunningInsertionEffect ,
143
147
} from './ReactFiberWorkLoop.new' ;
144
148
import {
@@ -1073,6 +1077,7 @@ function reappearLayoutEffectsOnFiber(node: Fiber) {
1073
1077
1074
1078
function commitTransitionProgress (
1075
1079
finishedRoot : FiberRoot ,
1080
+ suspenseBoundaries : Array < PendingSuspenseBoundaries > | null ,
1076
1081
offscreenFiber : Fiber ,
1077
1082
) {
1078
1083
if ( enableTransitionTracing ) {
@@ -1118,35 +1123,42 @@ function commitTransitionProgress(
1118
1123
}
1119
1124
1120
1125
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
+ } ) ;
1126
1133
} ) ;
1127
1134
}
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 ,
1142
1152
} ) ;
1143
- }
1153
+ } ) ;
1144
1154
}
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
+ }
1150
1162
} ) ;
1151
1163
}
1152
1164
}
@@ -2914,11 +2926,13 @@ function commitPassiveMountOnFiber(
2914
2926
}
2915
2927
2916
2928
if ( enableTransitionTracing ) {
2929
+ let suspenseMarkers = null ;
2917
2930
const isFallback = finishedWork . memoizedState ;
2918
2931
const queue = ( finishedWork . updateQueue : any ) ;
2919
2932
const rootMemoizedState = finishedRoot . current . memoizedState ;
2920
2933
2921
2934
if ( queue !== null ) {
2935
+ suspenseMarkers = queue . markerSuspenseBoundaries ;
2922
2936
// We have one instance of the pendingSuspenseBoundaries map.
2923
2937
// We only need one because we update it during the commit phase.
2924
2938
// We instantiate a new Map if we haven't already
@@ -2944,12 +2958,39 @@ function commitPassiveMountOnFiber(
2944
2958
prevTransitions . add ( transition ) ;
2945
2959
} ) ;
2946
2960
}
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
+ }
2947
2982
}
2948
2983
}
2949
2984
2950
- commitTransitionProgress ( finishedRoot , finishedWork ) ;
2985
+ commitTransitionProgress ( finishedRoot , suspenseMarkers , finishedWork ) ;
2951
2986
2952
- finishedWork . updateQueue = null ;
2987
+ if (
2988
+ queue === null ||
2989
+ queue . markerSuspenseBoundaries === null ||
2990
+ queue . markerSuspenseBoundaries . size === 0
2991
+ ) {
2992
+ finishedWork . updateQueue = null ;
2993
+ }
2953
2994
}
2954
2995
2955
2996
break ;
@@ -2975,6 +3016,25 @@ function commitPassiveMountOnFiber(
2975
3016
}
2976
3017
break ;
2977
3018
}
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
+ }
2978
3038
}
2979
3039
}
2980
3040
0 commit comments