@@ -35,6 +35,7 @@ import type {
35
35
} from './ReactFiberCacheComponent.new' ;
36
36
import type { UpdateQueue } from './ReactFiberClassUpdateQueue.new' ;
37
37
import type { RootState } from './ReactFiberRoot.new' ;
38
+ import type { TracingMarkerInstance } from './ReactFiberTracingMarkerComponent.new' ;
38
39
import {
39
40
enableSuspenseAvoidThisFallback ,
40
41
enableCPUSuspense ,
@@ -255,9 +256,12 @@ import {
255
256
getSuspendedCache ,
256
257
pushTransition ,
257
258
getOffscreenDeferredCache ,
258
- getSuspendedTransitions ,
259
+ getPendingTransitions ,
259
260
} from './ReactFiberTransition.new' ;
260
- import { pushTracingMarker } from './ReactFiberTracingMarkerComponent.new' ;
261
+ import {
262
+ getTracingMarkers ,
263
+ pushTracingMarker ,
264
+ } from './ReactFiberTracingMarkerComponent.new' ;
261
265
262
266
const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
263
267
@@ -891,6 +895,20 @@ function updateTracingMarkerComponent(
891
895
return null ;
892
896
}
893
897
898
+ // TODO: (luna) Only update the tracing marker if it's newly rendered or it's name changed.
899
+ // A tracing marker is only associated with the transitions that rendered
900
+ // or updated it, so we can create a new set of transitions each time
901
+ if ( current === null ) {
902
+ const currentTransitions = getPendingTransitions ( ) ;
903
+ if ( currentTransitions !== null ) {
904
+ const markerInstance : TracingMarkerInstance = {
905
+ transitions : new Set ( currentTransitions ) ,
906
+ pendingSuspenseBoundaries : new Map ( ) ,
907
+ } ;
908
+ workInProgress . stateNode = markerInstance ;
909
+ }
910
+ }
911
+
894
912
pushTracingMarker ( workInProgress ) ;
895
913
const nextChildren = workInProgress . pendingProps . children ;
896
914
reconcileChildren ( current , workInProgress , nextChildren , renderLanes ) ;
@@ -2093,10 +2111,13 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
2093
2111
) ;
2094
2112
workInProgress . memoizedState = SUSPENDED_MARKER ;
2095
2113
if ( enableTransitionTracing ) {
2096
- const currentTransitions = getSuspendedTransitions ( ) ;
2114
+ const currentTransitions = getPendingTransitions ( ) ;
2097
2115
if ( currentTransitions !== null ) {
2116
+ // If there are no transitions, we don't need to keep track of tracing markers
2117
+ const currentTracingMarkers = getTracingMarkers ( ) ;
2098
2118
const primaryChildUpdateQueue : OffscreenQueue = {
2099
2119
transitions : currentTransitions ,
2120
+ tracingMarkers : currentTracingMarkers ,
2100
2121
} ;
2101
2122
primaryChildFragment . updateQueue = primaryChildUpdateQueue ;
2102
2123
}
@@ -2177,10 +2198,12 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
2177
2198
? mountSuspenseOffscreenState ( renderLanes )
2178
2199
: updateSuspenseOffscreenState ( prevOffscreenState , renderLanes ) ;
2179
2200
if ( enableTransitionTracing ) {
2180
- const currentTransitions = getSuspendedTransitions ( ) ;
2201
+ const currentTransitions = getPendingTransitions ( ) ;
2181
2202
if ( currentTransitions !== null ) {
2203
+ const currentTracingMarkers = getTracingMarkers ( ) ;
2182
2204
const primaryChildUpdateQueue : OffscreenQueue = {
2183
2205
transitions : currentTransitions ,
2206
+ tracingMarkers : currentTracingMarkers ,
2184
2207
} ;
2185
2208
primaryChildFragment . updateQueue = primaryChildUpdateQueue ;
2186
2209
}
0 commit comments