Skip to content

Commit bcd87ff

Browse files
committed
old
1 parent 624cf77 commit bcd87ff

File tree

5 files changed

+254
-8
lines changed

5 files changed

+254
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ export function createFiberFromTracingMarker(
772772
const tracingMarkerInstance: TracingMarkerInstance = {
773773
transitions: null,
774774
pendingBoundaries: null,
775+
aborts: null,
776+
name: pendingProps.name,
775777
};
776778
fiber.stateNode = tracingMarkerInstance;
777779
return fiber;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ function updateTracingMarkerComponent(
979979
transitions: new Set(currentTransitions),
980980
pendingBoundaries: new Map(),
981981
name: workInProgress.pendingProps.name,
982+
aborts: null,
982983
};
983984
workInProgress.stateNode = markerInstance;
984985
}

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

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

3539
import {
3640
enableCreateEventHandleAPI,
@@ -146,6 +150,7 @@ import {
146150
addTransitionProgressCallbackToPendingTransition,
147151
addTransitionCompleteCallbackToPendingTransition,
148152
addMarkerProgressCallbackToPendingTransition,
153+
addMarkerIncompleteCallbackToPendingTransition,
149154
addMarkerCompleteCallbackToPendingTransition,
150155
setIsRunningInsertionEffect,
151156
} from './ReactFiberWorkLoop.old';
@@ -1132,6 +1137,91 @@ function commitLayoutEffectOnFiber(
11321137
}
11331138
}
11341139

1140+
function abortParentMarkerTransitions(
1141+
deletedFiber: Fiber,
1142+
nearestMountedAncestor: Fiber,
1143+
abort: TransitionAbort,
1144+
) {
1145+
let fiber = deletedFiber;
1146+
let isInDeletedTree = true;
1147+
while (fiber !== null) {
1148+
const instance = deletedFiber.stateNode;
1149+
switch (fiber.tag) {
1150+
case TracingMarkerComponent:
1151+
const transitions = instance.transitions;
1152+
1153+
const markerInstance = fiber.stateNode;
1154+
const markerTransitions = markerInstance.transitions;
1155+
const abortMarker = Array.from(transitions).some(transition =>
1156+
markerTransitions.has(transition),
1157+
);
1158+
1159+
if (abortMarker) {
1160+
if (markerInstance.aborts === null) {
1161+
markerInstance.aborts = new Set();
1162+
}
1163+
1164+
markerInstance.aborts.add(abort);
1165+
addMarkerIncompleteCallbackToPendingTransition(
1166+
fiber.memoizedProps.name,
1167+
transitions,
1168+
markerInstance.aborts,
1169+
);
1170+
1171+
// We only want to call onTransitionProgress when the marker hasn't been
1172+
// deleted
1173+
if (
1174+
!isInDeletedTree &&
1175+
markerInstance.pendingBoundaries !== null &&
1176+
markerInstance.pendingBoundaries.has(instance)
1177+
) {
1178+
markerInstance.pendingBoundaries.delete(instance);
1179+
1180+
addMarkerProgressCallbackToPendingTransition(
1181+
markerInstance.name,
1182+
transitions,
1183+
markerInstance.pendingBoundaries,
1184+
);
1185+
}
1186+
}
1187+
break;
1188+
case HostRoot:
1189+
const root = fiber.stateNode;
1190+
const incompleteTransitions = root.incompleteTransitions;
1191+
1192+
instance.transitions.forEach(transition => {
1193+
if (incompleteTransitions.has(transition)) {
1194+
const transitionInstance = incompleteTransitions.get(transition);
1195+
if (transitionInstance.aborts === null) {
1196+
transitionInstance.aborts = [];
1197+
}
1198+
transitionInstance.aborts.push(abort);
1199+
1200+
if (
1201+
transitionInstance.pendingBoundaries !== null &&
1202+
transitionInstance.pendingBoundaries.has(instance)
1203+
) {
1204+
transitionInstance.pendingBoundaries.delete(instance);
1205+
}
1206+
}
1207+
});
1208+
break;
1209+
default:
1210+
break;
1211+
}
1212+
1213+
if (
1214+
nearestMountedAncestor.deletions !== null &&
1215+
nearestMountedAncestor.deletions.includes(fiber)
1216+
) {
1217+
isInDeletedTree = false;
1218+
fiber = nearestMountedAncestor;
1219+
} else {
1220+
fiber = fiber.return;
1221+
}
1222+
}
1223+
}
1224+
11351225
function commitTransitionProgress(offscreenFiber: Fiber) {
11361226
if (enableTransitionTracing) {
11371227
// This function adds suspense boundaries to the root
@@ -1987,6 +2077,29 @@ function commitDeletionEffectsOnFiber(
19872077
const prevOffscreenSubtreeWasHidden = offscreenSubtreeWasHidden;
19882078
offscreenSubtreeWasHidden =
19892079
prevOffscreenSubtreeWasHidden || deletedFiber.memoizedState !== null;
2080+
2081+
if (enableTransitionTracing) {
2082+
// We need to mark this fiber's parents as deleted
2083+
const instance: OffscreenInstance = deletedFiber.stateNode;
2084+
const transitions = instance.transitions;
2085+
if (transitions !== null) {
2086+
let name = null;
2087+
const parent = deletedFiber.return;
2088+
if (
2089+
parent !== null &&
2090+
parent.tag === SuspenseComponent &&
2091+
parent.memoizedProps.unstable_name
2092+
) {
2093+
name = parent.memoizedProps.unstable_name;
2094+
}
2095+
2096+
abortParentMarkerTransitions(deletedFiber, nearestMountedAncestor, {
2097+
reason: 'suspense',
2098+
name,
2099+
});
2100+
}
2101+
}
2102+
19902103
recursivelyTraverseDeletionEffects(
19912104
finishedRoot,
19922105
nearestMountedAncestor,
@@ -2002,6 +2115,30 @@ function commitDeletionEffectsOnFiber(
20022115
}
20032116
break;
20042117
}
2118+
case TracingMarkerComponent: {
2119+
if (enableTransitionTracing) {
2120+
// We need to mark this fiber's parents as deleted
2121+
const instance: TracingMarkerInstance = deletedFiber.stateNode;
2122+
const transitions = instance.transitions;
2123+
if (transitions !== null) {
2124+
const abort = {
2125+
reason: 'marker',
2126+
name: deletedFiber.memoizedProps.name,
2127+
};
2128+
abortParentMarkerTransitions(
2129+
deletedFiber,
2130+
nearestMountedAncestor,
2131+
abort,
2132+
);
2133+
}
2134+
}
2135+
recursivelyTraverseDeletionEffects(
2136+
finishedRoot,
2137+
nearestMountedAncestor,
2138+
deletedFiber,
2139+
);
2140+
return;
2141+
}
20052142
default: {
20062143
recursivelyTraverseDeletionEffects(
20072144
finishedRoot,
@@ -2987,6 +3124,11 @@ function commitOffscreenPassiveMountEffects(
29873124
}
29883125

29893126
commitTransitionProgress(finishedWork);
3127+
3128+
if (!isHidden) {
3129+
instance.transitions = null;
3130+
instance.pendingMarkers = null;
3131+
}
29903132
}
29913133
}
29923134

@@ -3023,14 +3165,16 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
30233165
(instance.pendingBoundaries === null ||
30243166
instance.pendingBoundaries.size === 0)
30253167
) {
3026-
instance.transitions.forEach(transition => {
3168+
if (instance.aborts === null) {
30273169
addMarkerCompleteCallbackToPendingTransition(
30283170
finishedWork.memoizedProps.name,
30293171
instance.transitions,
30303172
);
3031-
});
3173+
}
30323174
instance.transitions = null;
30333175
instance.pendingBoundaries = null;
3176+
instance.aborts = null;
3177+
instance.name = null;
30343178
}
30353179
}
30363180

@@ -3146,7 +3290,9 @@ function commitPassiveMountOnFiber(
31463290
incompleteTransitions.forEach((markerInstance, transition) => {
31473291
const pendingBoundaries = markerInstance.pendingBoundaries;
31483292
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
3149-
addTransitionCompleteCallbackToPendingTransition(transition);
3293+
if (markerInstance.aborts === null) {
3294+
addTransitionCompleteCallbackToPendingTransition(transition);
3295+
}
31503296
incompleteTransitions.delete(transition);
31513297
}
31523298
});

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

Lines changed: 66 additions & 3 deletions
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+
{aborts: Array<TransitionAbort>, transitions: Set<Transition>},
31+
> | null,
2532
markerComplete: Map<string, Set<Transition>> | null,
2633
};
2734

@@ -37,9 +44,15 @@ export type BatchConfigTransition = {
3744
};
3845

3946
export type TracingMarkerInstance = {|
40-
pendingBoundaries: PendingBoundaries | null,
4147
transitions: Set<Transition> | null,
42-
name?: string,
48+
pendingBoundaries: PendingBoundaries | null,
49+
aborts: Array<TransitionAbort> | null,
50+
name: string | null,
51+
|};
52+
53+
export type TransitionAbort = {|
54+
reason: 'error' | 'unknown' | 'marker' | 'suspense',
55+
name?: string | null,
4356
|};
4457

4558
export type PendingBoundaries = Map<OffscreenInstance, SuspenseInfo>;
@@ -64,6 +77,7 @@ export function processTransitionCallbacks(
6477
if (onMarkerProgress != null && markerProgress !== null) {
6578
markerProgress.forEach((markerInstance, markerName) => {
6679
if (markerInstance.transitions !== null) {
80+
// TODO: Clone the suspense object so users can't modify it
6781
const pending =
6882
markerInstance.pendingBoundaries !== null
6983
? Array.from(markerInstance.pendingBoundaries.values())
@@ -96,6 +110,31 @@ export function processTransitionCallbacks(
96110
});
97111
}
98112

113+
const markerIncomplete = pendingTransitions.markerIncomplete;
114+
const onMarkerIncomplete = callbacks.onMarkerIncomplete;
115+
if (onMarkerIncomplete != null && markerIncomplete !== null) {
116+
markerIncomplete.forEach(({transitions, aborts}, markerName) => {
117+
transitions.forEach(transition => {
118+
const filteredAborts = [];
119+
aborts.forEach(deletion => {
120+
const filteredDeletion = getFilteredDeletion(deletion, endTime);
121+
if (filteredDeletion !== null) {
122+
filteredAborts.push(filteredDeletion);
123+
}
124+
});
125+
126+
if (filteredAborts.length > 0) {
127+
onMarkerIncomplete(
128+
transition.name,
129+
markerName,
130+
transition.startTime,
131+
filteredAborts,
132+
);
133+
}
134+
});
135+
});
136+
}
137+
99138
const transitionProgress = pendingTransitions.transitionProgress;
100139
const onTransitionProgress = callbacks.onTransitionProgress;
101140
if (onTransitionProgress != null && transitionProgress !== null) {
@@ -120,6 +159,28 @@ export function processTransitionCallbacks(
120159
}
121160
}
122161

162+
function getFilteredDeletion(abort: TransitionAbort, endTime: number) {
163+
switch (abort.reason) {
164+
case 'marker': {
165+
return {
166+
type: 'marker',
167+
name: abort.name,
168+
endTime,
169+
};
170+
}
171+
case 'suspense': {
172+
return {
173+
type: 'suspense',
174+
name: abort.name,
175+
endTime,
176+
};
177+
}
178+
default: {
179+
return null;
180+
}
181+
}
182+
}
183+
123184
// For every tracing marker, store a pointer to it. We will later access it
124185
// to get the set of suspense boundaries that need to resolve before the
125186
// tracing marker can be logged as complete
@@ -148,6 +209,8 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
148209
const markerInstance: TracingMarkerInstance = {
149210
transitions: new Set([transition]),
150211
pendingBoundaries: null,
212+
aborts: null,
213+
name: null,
151214
};
152215
root.incompleteTransitions.set(transition, markerInstance);
153216
}

0 commit comments

Comments
 (0)