Skip to content

Commit 5eb152f

Browse files
committed
transition tracing delete tracing marker
1 parent b4204ed commit 5eb152f

File tree

7 files changed

+608
-8
lines changed

7 files changed

+608
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,9 @@ export function createFiberFromTracingMarker(
772772
const tracingMarkerInstance: TracingMarkerInstance = {
773773
transitions: null,
774774
pendingBoundaries: null,
775+
deletions: null,
776+
parents: null,
777+
name: pendingProps.name,
775778
};
776779
fiber.stateNode = tracingMarkerInstance;
777780
return fiber;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,15 @@ function updateTracingMarkerComponent(
974974
// or updated it, so we can create a new set of transitions each time
975975
if (current === null) {
976976
const currentTransitions = getPendingTransitions();
977+
// TODO: What if the parent markers change?
978+
const parents = getMarkerInstances();
977979
if (currentTransitions !== null) {
978980
const markerInstance: TracingMarkerInstance = {
979981
transitions: new Set(currentTransitions),
980982
pendingBoundaries: new Map(),
981983
name: workInProgress.pendingProps.name,
984+
parents,
985+
deletions: null,
982986
};
983987
workInProgress.stateNode = markerInstance;
984988
}

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

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import type {
3030
import type {HookFlags} from './ReactHookEffectTags';
3131
import type {Cache} from './ReactFiberCacheComponent.new';
3232
import type {RootState} from './ReactFiberRoot.new';
33-
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
33+
import type {
34+
Transition,
35+
TracingMarkerInstance,
36+
} from './ReactFiberTracingMarkerComponent.new';
3437

3538
import {
3639
enableCreateEventHandleAPI,
@@ -146,6 +149,7 @@ import {
146149
addTransitionProgressCallbackToPendingTransition,
147150
addTransitionCompleteCallbackToPendingTransition,
148151
addMarkerProgressCallbackToPendingTransition,
152+
addMarkerIncompleteCallbackToPendingTransition,
149153
addMarkerCompleteCallbackToPendingTransition,
150154
setIsRunningInsertionEffect,
151155
} from './ReactFiberWorkLoop.new';
@@ -1987,6 +1991,20 @@ function commitDeletionEffectsOnFiber(
19871991
const prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden;
19881992
offscreenSubtreeWasHidden =
19891993
prevOffscreenSubtreeWasHidden || deletedFiber.memoizedState !== null;
1994+
1995+
if (enableTransitionTracing) {
1996+
// We need to mark this fiber's parents as deleted
1997+
const instance: OffscreenInstance = deletedFiber.stateNode;
1998+
const markers = instance.pendingMarkers;
1999+
if (markers !== null) {
2000+
markers.forEach(marker => {
2001+
if (marker.pendingBoundaries.has(instance)) {
2002+
marker.pendingBoundaries.delete(instance);
2003+
}
2004+
});
2005+
}
2006+
}
2007+
19902008
recursivelyTraverseDeletionEffects(
19912009
finishedRoot,
19922010
nearestMountedAncestor,
@@ -2002,6 +2020,58 @@ function commitDeletionEffectsOnFiber(
20022020
}
20032021
break;
20042022
}
2023+
case TracingMarkerComponent: {
2024+
if (enableTransitionTracing) {
2025+
// We need to mark this fiber's parents as deleted
2026+
const instance: TracingMarkerInstance = deletedFiber.stateNode;
2027+
const markers = instance.parents;
2028+
if (instance.transitions !== null) {
2029+
if (instance.deletions === null) {
2030+
instance.deletions = [];
2031+
}
2032+
instance.deletions.push({
2033+
type: 'marker',
2034+
name: deletedFiber.memoizedProps.name,
2035+
transitions: instance.transitions,
2036+
});
2037+
2038+
addMarkerIncompleteCallbackToPendingTransition(
2039+
instance.name,
2040+
instance.transitions,
2041+
instance.deletions,
2042+
);
2043+
2044+
if (markers !== null) {
2045+
markers.forEach(marker => {
2046+
if (marker.deletions === null) {
2047+
marker.deletions = [];
2048+
2049+
if (marker.name !== null) {
2050+
addMarkerIncompleteCallbackToPendingTransition(
2051+
marker.name,
2052+
instance.transitions,
2053+
marker.deletions,
2054+
);
2055+
}
2056+
}
2057+
2058+
marker.deletions.push({
2059+
type: 'marker',
2060+
name: deletedFiber.memoizedProps.name,
2061+
transitions: instance.transitions,
2062+
});
2063+
});
2064+
}
2065+
}
2066+
}
2067+
2068+
recursivelyTraverseDeletionEffects(
2069+
finishedRoot,
2070+
nearestMountedAncestor,
2071+
deletedFiber,
2072+
);
2073+
return;
2074+
}
20052075
default: {
20062076
recursivelyTraverseDeletionEffects(
20072077
finishedRoot,
@@ -3023,14 +3093,17 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
30233093
(instance.pendingBoundaries === null ||
30243094
instance.pendingBoundaries.size === 0)
30253095
) {
3026-
instance.transitions.forEach(transition => {
3096+
if (instance.deletions === null) {
30273097
addMarkerCompleteCallbackToPendingTransition(
30283098
finishedWork.memoizedProps.name,
30293099
instance.transitions,
30303100
);
3031-
});
3101+
}
30323102
instance.transitions = null;
30333103
instance.pendingBoundaries = null;
3104+
instance.deletions = null;
3105+
instance.parents = null;
3106+
instance.name = null;
30343107
}
30353108
}
30363109

@@ -3146,7 +3219,9 @@ function commitPassiveMountOnFiber(
31463219
incompleteTransitions.forEach((markerInstance, transition) => {
31473220
const pendingBoundaries = markerInstance.pendingBoundaries;
31483221
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
3149-
addTransitionCompleteCallbackToPendingTransition(transition);
3222+
if (markerInstance.deletions === null) {
3223+
addTransitionCompleteCallbackToPendingTransition(transition);
3224+
}
31503225
incompleteTransitions.delete(transition);
31513226
}
31523227
});

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ export type PendingTransitionCallbacks = {
2121
transitionStart: Array<Transition> | null,
2222
transitionProgress: Map<Transition, PendingBoundaries> | null,
2323
transitionComplete: Array<Transition> | null,
24-
markerProgress: Map<string, TracingMarkerInstance> | null,
24+
markerProgress: Map<
25+
string,
26+
{pendingBoundaries: PendingBoundaries, transitions: Set<Transition>},
27+
> | null,
28+
markerIncomplete: Map<
29+
string,
30+
{deletions: Array<TransitionDeletion>, transitions: Set<Transition>},
31+
> | null,
2532
markerComplete: Map<string, Set<Transition>> | null,
2633
};
2734

@@ -39,7 +46,16 @@ export type BatchConfigTransition = {
3946
export type TracingMarkerInstance = {|
4047
pendingBoundaries: PendingBoundaries | null,
4148
transitions: Set<Transition> | null,
49+
deletions: Array<TransitionDeletion> | null,
50+
parents: Array<TracingMarkerInstance> | null,
51+
name: string | null,
52+
|};
53+
54+
export type TransitionDeletion = {|
55+
type: 'error' | 'unknown' | 'marker' | 'suspense',
4256
name?: string,
57+
endTime: number,
58+
transitions: Set<Transition>,
4359
|};
4460

4561
export type PendingBoundaries = Map<OffscreenInstance, SuspenseInfo>;
@@ -64,6 +80,7 @@ export function processTransitionCallbacks(
6480
if (onMarkerProgress != null && markerProgress !== null) {
6581
markerProgress.forEach((markerInstance, markerName) => {
6682
if (markerInstance.transitions !== null) {
83+
// TODO: Clone the suspense object so users can't modify it
6784
const pending =
6885
markerInstance.pendingBoundaries !== null
6986
? Array.from(markerInstance.pendingBoundaries.values())
@@ -96,6 +113,30 @@ export function processTransitionCallbacks(
96113
});
97114
}
98115

116+
const markerIncomplete = pendingTransitions.markerIncomplete;
117+
const onMarkerIncomplete = callbacks.onMarkerIncomplete;
118+
if (onMarkerIncomplete != null && markerIncomplete !== null) {
119+
markerIncomplete.forEach(({transitions, deletions}, markerName) => {
120+
transitions.forEach(transition => {
121+
const filteredDeletions = [];
122+
deletions.forEach(deletion => {
123+
if (deletion.transitions.has(transition)) {
124+
const filteredDeletion = getFilteredDeletion(deletion, endTime);
125+
if (filteredDeletion !== null) {
126+
filteredDeletions.push(filteredDeletion);
127+
}
128+
}
129+
});
130+
onMarkerIncomplete(
131+
transition.name,
132+
markerName,
133+
transition.startTime,
134+
filteredDeletions,
135+
);
136+
});
137+
});
138+
}
139+
99140
const transitionProgress = pendingTransitions.transitionProgress;
100141
const onTransitionProgress = callbacks.onTransitionProgress;
101142
if (onTransitionProgress != null && transitionProgress !== null) {
@@ -120,6 +161,21 @@ export function processTransitionCallbacks(
120161
}
121162
}
122163

164+
function getFilteredDeletion(deletion: TransitionDeletion, endTime: number) {
165+
switch (deletion.type) {
166+
case 'marker': {
167+
return {
168+
type: deletion.type,
169+
name: deletion.name,
170+
endTime,
171+
};
172+
}
173+
default: {
174+
return null;
175+
}
176+
}
177+
}
178+
123179
// For every tracing marker, store a pointer to it. We will later access it
124180
// to get the set of suspense boundaries that need to resolve before the
125181
// tracing marker can be logged as complete
@@ -148,6 +204,9 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
148204
const markerInstance: TracingMarkerInstance = {
149205
transitions: new Set([transition]),
150206
pendingBoundaries: null,
207+
deletions: null,
208+
parents: null,
209+
name: null,
151210
};
152211
root.incompleteTransitions.set(transition, markerInstance);
153212
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
PendingTransitionCallbacks,
1919
PendingBoundaries,
2020
Transition,
21+
TransitionDeletion,
2122
} from './ReactFiberTracingMarkerComponent.new';
2223
import type {OffscreenInstance} from './ReactFiberOffscreenComponent';
2324

@@ -342,6 +343,7 @@ export function addTransitionStartCallbackToPendingTransition(
342343
transitionProgress: null,
343344
transitionComplete: null,
344345
markerProgress: null,
346+
markerIncomplete: null,
345347
markerComplete: null,
346348
};
347349
}
@@ -357,7 +359,7 @@ export function addTransitionStartCallbackToPendingTransition(
357359
export function addMarkerProgressCallbackToPendingTransition(
358360
markerName: string,
359361
transitions: Set<Transition>,
360-
pendingBoundaries: PendingBoundaries | null,
362+
pendingBoundaries: PendingBoundaries,
361363
) {
362364
if (enableTransitionTracing) {
363365
if (currentPendingTransitionCallbacks === null) {
@@ -366,6 +368,7 @@ export function addMarkerProgressCallbackToPendingTransition(
366368
transitionProgress: null,
367369
transitionComplete: null,
368370
markerProgress: new Map(),
371+
markerIncomplete: null,
369372
markerComplete: null,
370373
};
371374
}
@@ -381,6 +384,34 @@ export function addMarkerProgressCallbackToPendingTransition(
381384
}
382385
}
383386

387+
export function addMarkerIncompleteCallbackToPendingTransition(
388+
markerName: string,
389+
transitions: Set<Transition>,
390+
deletions: Array<TransitionDeletion>,
391+
) {
392+
if (enableTransitionTracing) {
393+
if (currentPendingTransitionCallbacks === null) {
394+
currentPendingTransitionCallbacks = {
395+
transitionStart: null,
396+
transitionProgress: null,
397+
transitionComplete: null,
398+
markerProgress: null,
399+
markerIncomplete: new Map(),
400+
markerComplete: null,
401+
};
402+
}
403+
404+
if (currentPendingTransitionCallbacks.markerIncomplete === null) {
405+
currentPendingTransitionCallbacks.markerIncomplete = new Map();
406+
}
407+
408+
currentPendingTransitionCallbacks.markerIncomplete.set(markerName, {
409+
transitions,
410+
deletions,
411+
});
412+
}
413+
}
414+
384415
export function addMarkerCompleteCallbackToPendingTransition(
385416
markerName: string,
386417
transitions: Set<Transition>,
@@ -392,6 +423,7 @@ export function addMarkerCompleteCallbackToPendingTransition(
392423
transitionProgress: null,
393424
transitionComplete: null,
394425
markerProgress: null,
426+
markerIncomplete: null,
395427
markerComplete: new Map(),
396428
};
397429
}
@@ -418,6 +450,7 @@ export function addTransitionProgressCallbackToPendingTransition(
418450
transitionProgress: new Map(),
419451
transitionComplete: null,
420452
markerProgress: null,
453+
markerIncomplete: null,
421454
markerComplete: null,
422455
};
423456
}
@@ -443,6 +476,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
443476
transitionProgress: null,
444477
transitionComplete: [],
445478
markerProgress: null,
479+
markerIncomplete: null,
446480
markerComplete: null,
447481
};
448482
}

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ export type TransitionTracingCallbacks = {
292292
deletions: Array<{
293293
type: string,
294294
name?: string,
295-
newName?: string,
296295
endTime: number,
297296
}>,
298297
) => void,
@@ -315,7 +314,6 @@ export type TransitionTracingCallbacks = {
315314
deletions: Array<{
316315
type: string,
317316
name?: string,
318-
newName?: string,
319317
endTime: number,
320318
}>,
321319
) => void,

0 commit comments

Comments
 (0)