@@ -35,6 +35,7 @@ import type {
3535} from './ReactFiberCacheComponent.new' ;
3636import type { UpdateQueue } from './ReactFiberClassUpdateQueue.new' ;
3737import type { RootState } from './ReactFiberRoot.new' ;
38+ import type { TracingMarkerInstance } from './ReactFiberTracingMarkerComponent.new' ;
3839import {
3940 enableSuspenseAvoidThisFallback ,
4041 enableCPUSuspense ,
@@ -255,9 +256,12 @@ import {
255256 getSuspendedCache ,
256257 pushTransition ,
257258 getOffscreenDeferredCache ,
258- getSuspendedTransitions ,
259+ getPendingTransitions ,
259260} from './ReactFiberTransition.new' ;
260- import { pushTracingMarker } from './ReactFiberTracingMarkerComponent.new' ;
261+ import {
262+ getTracingMarkers ,
263+ pushTracingMarker ,
264+ } from './ReactFiberTracingMarkerComponent.new' ;
261265
262266const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
263267
@@ -891,6 +895,20 @@ function updateTracingMarkerComponent(
891895 return null ;
892896 }
893897
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+
894912 pushTracingMarker ( workInProgress ) ;
895913 const nextChildren = workInProgress . pendingProps . children ;
896914 reconcileChildren ( current , workInProgress , nextChildren , renderLanes ) ;
@@ -2093,10 +2111,13 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20932111 ) ;
20942112 workInProgress . memoizedState = SUSPENDED_MARKER ;
20952113 if ( enableTransitionTracing ) {
2096- const currentTransitions = getSuspendedTransitions ( ) ;
2114+ const currentTransitions = getPendingTransitions ( ) ;
20972115 if ( currentTransitions !== null ) {
2116+ // If there are no transitions, we don't need to keep track of tracing markers
2117+ const currentTracingMarkers = getTracingMarkers ( ) ;
20982118 const primaryChildUpdateQueue : OffscreenQueue = {
20992119 transitions : currentTransitions ,
2120+ tracingMarkers : currentTracingMarkers ,
21002121 } ;
21012122 primaryChildFragment . updateQueue = primaryChildUpdateQueue ;
21022123 }
@@ -2177,10 +2198,12 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21772198 ? mountSuspenseOffscreenState ( renderLanes )
21782199 : updateSuspenseOffscreenState ( prevOffscreenState , renderLanes ) ;
21792200 if ( enableTransitionTracing ) {
2180- const currentTransitions = getSuspendedTransitions ( ) ;
2201+ const currentTransitions = getPendingTransitions ( ) ;
21812202 if ( currentTransitions !== null ) {
2203+ const currentTracingMarkers = getTracingMarkers ( ) ;
21822204 const primaryChildUpdateQueue : OffscreenQueue = {
21832205 transitions : currentTransitions ,
2206+ tracingMarkers : currentTracingMarkers ,
21842207 } ;
21852208 primaryChildFragment . updateQueue = primaryChildUpdateQueue ;
21862209 }
0 commit comments