Skip to content

Commit d029eed

Browse files
committed
old
1 parent 832a693 commit d029eed

File tree

6 files changed

+189
-16
lines changed

6 files changed

+189
-16
lines changed

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

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

packages/react-reconciler/src/ReactFiberBeginWork.old.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
pendingSuspenseBoundaries: new Map(),
981983
name: workInProgress.pendingProps.name,
984+
parents,
985+
deletions: null,
982986
};
983987
workInProgress.stateNode = markerInstance;
984988
}

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

Lines changed: 73 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';
@@ -2937,7 +2938,9 @@ function commitPassiveMountOnFiber(
29372938
incompleteTransitions.forEach((markerInstance, transition) => {
29382939
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
29392940
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
2940-
addTransitionCompleteCallbackToPendingTransition(transition);
2941+
if (markerInstance.deletions === null) {
2942+
addTransitionCompleteCallbackToPendingTransition(transition);
2943+
}
29412944
incompleteTransitions.delete(transition);
29422945
}
29432946
});
@@ -3059,19 +3062,75 @@ function commitPassiveMountOnFiber(
30593062
// Get the transitions that were initiatized during the render
30603063
// and add a start transition callback for each of them
30613064
const instance = finishedWork.stateNode;
3062-
if (
3063-
instance.transitions !== null &&
3064-
(instance.pendingSuspenseBoundaries === null ||
3065-
instance.pendingSuspenseBoundaries.size === 0)
3066-
) {
3067-
instance.transitions.forEach(transition => {
3068-
addMarkerCompleteCallbackToPendingTransition({
3069-
transition,
3070-
name: finishedWork.memoizedProps.name,
3071-
});
3072-
});
3073-
instance.transitions = null;
3074-
instance.pendingSuspenseBoundaries = null;
3065+
if (instance.transitions !== null) {
3066+
if (finishedWork.alternate !== null) {
3067+
const prevName = finishedWork.alternate.memoizedProps.name;
3068+
const nextName = finishedWork.memoizedProps.name;
3069+
3070+
// The transition should be marked as incomplete if the name changed
3071+
if (prevName !== nextName) {
3072+
if (!instance.deletions) {
3073+
instance.deletions = [];
3074+
3075+
addMarkerIncompleteCallbackToPendingTransition(
3076+
prevName,
3077+
instance.transitions,
3078+
instance.deletions,
3079+
);
3080+
}
3081+
3082+
const deletion = {
3083+
type: 'marker',
3084+
name: prevName,
3085+
newName: nextName,
3086+
// we'll filter the transitions that need to have this deletion
3087+
// during the callback stage
3088+
transitions: instance.transitions,
3089+
};
3090+
3091+
instance.deletions.push(deletion);
3092+
if (instance.parents !== null) {
3093+
instance.parents.forEach(marker => {
3094+
const parentDeletion = {
3095+
type: 'marker',
3096+
name: prevName,
3097+
transitions: marker.transitions,
3098+
};
3099+
3100+
if (!marker.deletions) {
3101+
marker.deletions = [];
3102+
// we only add the incomplete callback the first time the marker is incomplete
3103+
if (marker.name !== null) {
3104+
addMarkerIncompleteCallbackToPendingTransition(
3105+
marker.name,
3106+
instance.transitions,
3107+
marker.deletions,
3108+
);
3109+
}
3110+
}
3111+
3112+
marker.deletions.push(parentDeletion);
3113+
});
3114+
}
3115+
}
3116+
}
3117+
3118+
if (
3119+
instance.pendingSuspenseBoundaries === null ||
3120+
instance.pendingSuspenseBoundaries.size === 0
3121+
) {
3122+
if (instance.deletions === null) {
3123+
instance.transitions.forEach(transition => {
3124+
addMarkerCompleteCallbackToPendingTransition({
3125+
transition,
3126+
name: finishedWork.memoizedProps.name,
3127+
});
3128+
});
3129+
}
3130+
instance.transitions = null;
3131+
instance.pendingSuspenseBoundaries = null;
3132+
instance.deletions = null;
3133+
}
30753134
}
30763135
}
30773136
break;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,11 @@ function completeWork(
16051605
}
16061606
bubbleProperties(workInProgress);
16071607

1608+
const prevName = current !== null ? current.memoizedProps.name : null;
1609+
const nextName = workInProgress.memoizedProps.name;
16081610
if (
16091611
current === null ||
1612+
prevName !== nextName ||
16101613
(workInProgress.subtreeFlags & Visibility) !== NoFlags
16111614
) {
16121615
// If any of our suspense children toggle visibility, this means that

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ export type PendingTransitionCallbacks = {
2626
transitionStart: Array<Transition> | null,
2727
transitionProgress: Map<Transition, PendingSuspenseBoundaries> | null,
2828
transitionComplete: Array<Transition> | null,
29-
markerProgress: Map<string, TracingMarkerInstance> | null,
29+
markerProgress: Map<
30+
string,
31+
{
32+
pendingSuspenseBoundaries: PendingSuspenseBoundaries,
33+
transitions: Set<Transition>,
34+
},
35+
> | null,
36+
markerIncomplete: Map<
37+
string,
38+
{deletions: Array<TransitionDeletion>, transitions: Set<Transition>},
39+
> | null,
3040
markerComplete: Array<MarkerTransition> | null,
3141
};
3242

@@ -44,7 +54,17 @@ export type BatchConfigTransition = {
4454
export type TracingMarkerInstance = {|
4555
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
4656
transitions: Set<Transition> | null,
57+
deletions: Array<TransitionDeletion> | null,
58+
parents: Array<TracingMarkerInstance> | null,
59+
name: string | null,
60+
|};
61+
62+
export type TransitionDeletion = {|
63+
type: 'error' | 'unknown' | 'marker' | 'suspense',
4764
name?: string,
65+
newName?: string,
66+
endTime: number,
67+
transitions: Set<Transition>,
4868
|};
4969

5070
export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;
@@ -70,6 +90,7 @@ export function processTransitionCallbacks(
7090
if (onMarkerProgress != null && markerProgress !== null) {
7191
markerProgress.forEach((markerInstance, markerName) => {
7292
if (markerInstance.transitions !== null) {
93+
// TODO: Clone the suspense object so users can't modify it
7394
const pending =
7495
markerInstance.pendingSuspenseBoundaries !== null
7596
? Array.from(markerInstance.pendingSuspenseBoundaries.values())
@@ -101,6 +122,30 @@ export function processTransitionCallbacks(
101122
});
102123
}
103124

125+
const markerIncomplete = pendingTransitions.markerIncomplete;
126+
const onMarkerIncomplete = callbacks.onMarkerIncomplete;
127+
if (onMarkerIncomplete != null && markerIncomplete !== null) {
128+
markerIncomplete.forEach(({transitions, deletions}, markerName) => {
129+
transitions.forEach(transition => {
130+
const filteredDeletions = [];
131+
deletions.forEach(deletion => {
132+
if (deletion.transitions.has(transition)) {
133+
const filteredDeletion = getFilteredDeletion(deletion, endTime);
134+
if (filteredDeletion !== null) {
135+
filteredDeletions.push(filteredDeletion);
136+
}
137+
}
138+
});
139+
onMarkerIncomplete(
140+
transition.name,
141+
markerName,
142+
transition.startTime,
143+
filteredDeletions,
144+
);
145+
});
146+
});
147+
}
148+
104149
const transitionProgress = pendingTransitions.transitionProgress;
105150
const onTransitionProgress = callbacks.onTransitionProgress;
106151
if (onTransitionProgress != null && transitionProgress !== null) {
@@ -130,6 +175,28 @@ export function processTransitionCallbacks(
130175
}
131176
}
132177

178+
function getFilteredDeletion(deletion: TransitionDeletion, endTime: number) {
179+
switch (deletion.type) {
180+
case 'marker': {
181+
return deletion.newName
182+
? {
183+
type: deletion.type,
184+
name: deletion.name,
185+
newName: deletion.newName,
186+
endTime,
187+
}
188+
: {
189+
type: deletion.type,
190+
name: deletion.name,
191+
endTime,
192+
};
193+
}
194+
default: {
195+
return null;
196+
}
197+
}
198+
}
199+
133200
// For every tracing marker, store a pointer to it. We will later access it
134201
// to get the set of suspense boundaries that need to resolve before the
135202
// tracing marker can be logged as complete
@@ -158,6 +225,9 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
158225
const markerInstance: TracingMarkerInstance = {
159226
transitions: new Set([transition]),
160227
pendingSuspenseBoundaries: null,
228+
deletions: null,
229+
parents: null,
230+
name: null,
161231
};
162232
root.incompleteTransitions.set(transition, markerInstance);
163233
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
MarkerTransition,
2020
PendingSuspenseBoundaries,
2121
Transition,
22+
TransitionDeletion,
2223
} from './ReactFiberTracingMarkerComponent.old';
2324
import type {OffscreenInstance} from './ReactFiberOffscreenComponent';
2425

@@ -343,6 +344,7 @@ export function addTransitionStartCallbackToPendingTransition(
343344
transitionProgress: null,
344345
transitionComplete: null,
345346
markerProgress: null,
347+
markerIncomplete: null,
346348
markerComplete: null,
347349
};
348350
}
@@ -358,7 +360,7 @@ export function addTransitionStartCallbackToPendingTransition(
358360
export function addMarkerProgressCallbackToPendingTransition(
359361
markerName: string,
360362
transitions: Set<Transition>,
361-
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
363+
pendingSuspenseBoundaries: PendingSuspenseBoundaries,
362364
) {
363365
if (enableTransitionTracing) {
364366
if (currentPendingTransitionCallbacks === null) {
@@ -367,6 +369,7 @@ export function addMarkerProgressCallbackToPendingTransition(
367369
transitionProgress: null,
368370
transitionComplete: null,
369371
markerProgress: new Map(),
372+
markerIncomplete: null,
370373
markerComplete: null,
371374
};
372375
}
@@ -382,6 +385,34 @@ export function addMarkerProgressCallbackToPendingTransition(
382385
}
383386
}
384387

388+
export function addMarkerIncompleteCallbackToPendingTransition(
389+
markerName: string,
390+
transitions: Set<Transition>,
391+
deletions: Array<TransitionDeletion>,
392+
) {
393+
if (enableTransitionTracing) {
394+
if (currentPendingTransitionCallbacks === null) {
395+
currentPendingTransitionCallbacks = {
396+
transitionStart: null,
397+
transitionProgress: null,
398+
transitionComplete: null,
399+
markerProgress: null,
400+
markerIncomplete: new Map(),
401+
markerComplete: null,
402+
};
403+
}
404+
405+
if (currentPendingTransitionCallbacks.markerIncomplete === null) {
406+
currentPendingTransitionCallbacks.markerIncomplete = new Map();
407+
}
408+
409+
currentPendingTransitionCallbacks.markerIncomplete.set(markerName, {
410+
transitions,
411+
deletions,
412+
});
413+
}
414+
}
415+
385416
export function addMarkerCompleteCallbackToPendingTransition(
386417
transition: MarkerTransition,
387418
) {
@@ -392,6 +423,7 @@ export function addMarkerCompleteCallbackToPendingTransition(
392423
transitionProgress: null,
393424
transitionComplete: null,
394425
markerProgress: null,
426+
markerIncomplete: null,
395427
markerComplete: [],
396428
};
397429
}
@@ -415,6 +447,7 @@ export function addTransitionProgressCallbackToPendingTransition(
415447
transitionProgress: new Map(),
416448
transitionComplete: null,
417449
markerProgress: null,
450+
markerIncomplete: null,
418451
markerComplete: null,
419452
};
420453
}
@@ -440,6 +473,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
440473
transitionProgress: null,
441474
transitionComplete: [],
442475
markerProgress: null,
476+
markerIncomplete: null,
443477
markerComplete: null,
444478
};
445479
}

0 commit comments

Comments
 (0)