Skip to content

Commit ddc1ba6

Browse files
committed
old
1 parent 73666be commit ddc1ba6

6 files changed

+156
-16
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+
deletions: 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+
deletions: null,
982983
};
983984
workInProgress.stateNode = markerInstance;
984985
}

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

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ import {
146146
addTransitionProgressCallbackToPendingTransition,
147147
addTransitionCompleteCallbackToPendingTransition,
148148
addMarkerProgressCallbackToPendingTransition,
149+
addMarkerIncompleteCallbackToPendingTransition,
149150
addMarkerCompleteCallbackToPendingTransition,
150151
setIsRunningInsertionEffect,
151152
} from './ReactFiberWorkLoop.old';
@@ -3018,19 +3019,51 @@ function commitTracingMarkerPassiveMountEffect(finishedWork: Fiber) {
30183019
// Get the transitions that were initiatized during the render
30193020
// and add a start transition callback for each of them
30203021
const instance = finishedWork.stateNode;
3021-
if (
3022-
instance.transitions !== null &&
3023-
(instance.pendingBoundaries === null ||
3024-
instance.pendingBoundaries.size === 0)
3025-
) {
3026-
instance.transitions.forEach(transition => {
3027-
addMarkerCompleteCallbackToPendingTransition(
3028-
finishedWork.memoizedProps.name,
3029-
instance.transitions,
3030-
);
3031-
});
3032-
instance.transitions = null;
3033-
instance.pendingBoundaries = null;
3022+
if (instance.transitions !== null) {
3023+
if (finishedWork.alternate !== null) {
3024+
const prevName = finishedWork.alternate.memoizedProps.name;
3025+
const nextName = finishedWork.memoizedProps.name;
3026+
3027+
// The transition should be marked as incomplete if the name changed
3028+
if (prevName !== nextName) {
3029+
if (!instance.deletions) {
3030+
instance.deletions = [];
3031+
3032+
addMarkerIncompleteCallbackToPendingTransition(
3033+
prevName,
3034+
instance.transitions,
3035+
instance.deletions,
3036+
);
3037+
}
3038+
3039+
const deletion = {
3040+
type: 'marker',
3041+
name: prevName,
3042+
newName: nextName,
3043+
// we'll filter the transitions that need to have this deletion
3044+
// during the callback stage
3045+
transitions: instance.transitions,
3046+
};
3047+
3048+
instance.deletions.push(deletion);
3049+
}
3050+
}
3051+
3052+
if (
3053+
instance.transitions !== null &&
3054+
(instance.pendingBoundaries === null ||
3055+
instance.pendingBoundaries.size === 0)
3056+
) {
3057+
if (instance.deletions === null) {
3058+
addMarkerCompleteCallbackToPendingTransition(
3059+
finishedWork.memoizedProps.name,
3060+
instance.transitions,
3061+
);
3062+
}
3063+
instance.transitions = null;
3064+
instance.pendingBoundaries = null;
3065+
instance.deletions = null;
3066+
}
30343067
}
30353068
}
30363069

@@ -3146,7 +3179,9 @@ function commitPassiveMountOnFiber(
31463179
incompleteTransitions.forEach((markerInstance, transition) => {
31473180
const pendingBoundaries = markerInstance.pendingBoundaries;
31483181
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
3149-
addTransitionCompleteCallbackToPendingTransition(transition);
3182+
if (markerInstance.deletions === null) {
3183+
addTransitionCompleteCallbackToPendingTransition(transition);
3184+
}
31503185
incompleteTransitions.delete(transition);
31513186
}
31523187
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,11 @@ function completeWork(
15901590
}
15911591
bubbleProperties(workInProgress);
15921592

1593+
const prevName = current !== null ? current.memoizedProps.name : null;
1594+
const nextName = workInProgress.memoizedProps.name;
15931595
if (
15941596
current === null ||
1597+
prevName !== nextName ||
15951598
(workInProgress.subtreeFlags & Visibility) !== NoFlags
15961599
) {
15971600
// If any of our suspense children toggle visibility, this means that

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

Lines changed: 66 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+
name: string | null,
51+
|};
52+
53+
export type TransitionDeletion = {|
54+
type: 'error' | 'unknown' | 'marker' | 'suspense',
4255
name?: string,
56+
newName?: 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,28 @@ export function processTransitionCallbacks(
120161
}
121162
}
122163

164+
function getFilteredDeletion(deletion: TransitionDeletion, endTime: number) {
165+
switch (deletion.type) {
166+
case 'marker': {
167+
return deletion.newName
168+
? {
169+
type: deletion.type,
170+
name: deletion.name,
171+
newName: deletion.newName,
172+
endTime,
173+
}
174+
: {
175+
type: deletion.type,
176+
name: deletion.name,
177+
endTime,
178+
};
179+
}
180+
default: {
181+
return null;
182+
}
183+
}
184+
}
185+
123186
// For every tracing marker, store a pointer to it. We will later access it
124187
// to get the set of suspense boundaries that need to resolve before the
125188
// tracing marker can be logged as complete
@@ -148,6 +211,8 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
148211
const markerInstance: TracingMarkerInstance = {
149212
transitions: new Set([transition]),
150213
pendingBoundaries: null,
214+
deletions: null,
215+
name: null,
151216
};
152217
root.incompleteTransitions.set(transition, markerInstance);
153218
}

packages/react-reconciler/src/ReactFiberWorkLoop.old.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.old';
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
}

0 commit comments

Comments
 (0)