Skip to content

Commit 78d241c

Browse files
committed
add tracing marker push and pop
1 parent 7a5b822 commit 78d241c

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.new.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ import {
253253
getOffscreenDeferredCache,
254254
getSuspendedTransitions,
255255
} from './ReactFiberTransition.new';
256+
import {pushTracingMarker} from './ReactFiberTracingMarkerComponent.new';
256257

257258
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
258259

@@ -882,6 +883,7 @@ function updateTracingMarkerComponent(
882883
return null;
883884
}
884885

886+
pushTracingMarker(workInProgress);
885887
const nextChildren = workInProgress.pendingProps.children;
886888
reconcileChildren(current, workInProgress, nextChildren, renderLanes);
887889
return workInProgress.child;
@@ -3645,6 +3647,11 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
36453647
}
36463648
break;
36473649
}
3650+
case TracingMarkerComponent: {
3651+
if (enableTransitionTracing) {
3652+
pushTracingMarker(workInProgress);
3653+
}
3654+
}
36483655
}
36493656
return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
36503657
}

packages/react-reconciler/src/ReactFiberCompleteWork.new.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ import {transferActualDuration} from './ReactProfilerTimer.new';
165165
import {popCacheProvider} from './ReactFiberCacheComponent.new';
166166
import {popTreeContext} from './ReactFiberTreeContext.new';
167167
import {popRootTransition, popTransition} from './ReactFiberTransition.new';
168+
import {popTracingMarker} from './ReactFiberTracingMarkerComponent.new';
168169

169170
function markUpdate(workInProgress: Fiber) {
170171
// Tag the fiber with an update effect. This turns a Placement into
@@ -1585,6 +1586,7 @@ function completeWork(
15851586
case TracingMarkerComponent: {
15861587
if (enableTransitionTracing) {
15871588
// Bubble subtree flags before so we can set the flag property
1589+
popTracingMarker(workInProgress);
15881590
bubbleProperties(workInProgress);
15891591
}
15901592
return null;

packages/react-reconciler/src/ReactFiberTracingMarkerComponent.new.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
import type {TransitionTracingCallbacks, Fiber} from './ReactInternalTypes';
1111
import type {OffscreenInstance} from './ReactFiberOffscreenComponent';
12+
import type {StackCursor} from './ReactFiberStack.new';
1213

1314
import {enableTransitionTracing} from 'shared/ReactFeatureFlags';
15+
import {createCursor, push, pop} from './ReactFiberStack.new';
1416

1517
export type SuspenseInfo = {name: string | null};
1618

@@ -65,9 +67,36 @@ export function processTransitionCallbacks(
6567
transition.startTime,
6668
endTime,
6769
);
68-
}
69-
});
70-
}
70+
// For every tracing marker, store a pointer to it. We will later access it
71+
// to get the set of suspense boundaries that need to resolve before the
72+
// tracing marker can be logged as complete
73+
// This code lives separate from the ReactFiberTransition code because
74+
// we push and pop on the tracing marker, not the suspense boundary
75+
const tracingMarkerStack: StackCursor<Array<Fiber> | null> = createCursor(null);
76+
77+
export function pushTracingMarker(workInProgress: Fiber): void {
78+
if (enableTransitionTracing) {
79+
if (tracingMarkerStack.current === null) {
80+
push(tracingMarkerStack, [workInProgress], workInProgress);
81+
} else {
82+
push(
83+
tracingMarkerStack,
84+
tracingMarkerStack.current.concat(workInProgress),
85+
workInProgress,
86+
);
7187
}
7288
}
7389
}
90+
91+
export function popTracingMarker(workInProgress: Fiber): void {
92+
if (enableTransitionTracing) {
93+
pop(tracingMarkerStack, workInProgress);
94+
}
95+
}
96+
97+
export function getTracingMarkers(): Array<Fiber> | null {
98+
if (enableTransitionTracing) {
99+
return tracingMarkerStack.current;
100+
}
101+
return null;
102+
}

packages/react-reconciler/src/ReactFiberUnwindWork.new.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ import {
2525
OffscreenComponent,
2626
LegacyHiddenComponent,
2727
CacheComponent,
28+
TracingMarkerComponent,
2829
} from './ReactWorkTags';
2930
import {DidCapture, NoFlags, ShouldCapture} from './ReactFiberFlags';
3031
import {NoMode, ProfileMode} from './ReactTypeOfMode';
31-
import {enableProfilerTimer, enableCache} from 'shared/ReactFeatureFlags';
32+
import {
33+
enableProfilerTimer,
34+
enableCache,
35+
enableTransitionTracing,
36+
} from 'shared/ReactFeatureFlags';
3237

3338
import {popHostContainer, popHostContext} from './ReactFiberHostContext.new';
3439
import {popSuspenseContext} from './ReactFiberSuspenseContext.new';
@@ -44,6 +49,7 @@ import {popCacheProvider} from './ReactFiberCacheComponent.new';
4449
import {transferActualDuration} from './ReactProfilerTimer.new';
4550
import {popTreeContext} from './ReactFiberTreeContext.new';
4651
import {popRootTransition, popTransition} from './ReactFiberTransition.new';
52+
import {popTracingMarker} from './ReactFiberTracingMarkerComponent.new';
4753

4854
function unwindWork(
4955
current: Fiber | null,
@@ -154,6 +160,11 @@ function unwindWork(
154160
popCacheProvider(workInProgress, cache);
155161
}
156162
return null;
163+
case TracingMarkerComponent:
164+
if (enableTransitionTracing) {
165+
popTracingMarker(workInProgress);
166+
}
167+
return null;
157168
default:
158169
return null;
159170
}
@@ -217,6 +228,11 @@ function unwindInterruptedWork(
217228
popCacheProvider(interruptedWork, cache);
218229
}
219230
break;
231+
case TracingMarkerComponent:
232+
if (enableTransitionTracing) {
233+
popTracingMarker(interruptedWork);
234+
}
235+
break;
220236
default:
221237
break;
222238
}

0 commit comments

Comments
 (0)