Skip to content

Commit

Permalink
old
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Jul 6, 2022
1 parent fc8e91e commit ffbfaa0
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ export function createFiberFromTracingMarker(
const tracingMarkerInstance: TracingMarkerInstance = {
transitions: null,
pendingSuspenseBoundaries: null,
hasUpdate: false,
};
fiber.stateNode = tracingMarkerInstance;
return fiber;
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ function updateTracingMarkerComponent(
const markerInstance: TracingMarkerInstance = {
transitions: new Set(currentTransitions),
pendingSuspenseBoundaries: new Map(),
hasUpdate: false,
};
workInProgress.stateNode = markerInstance;
}
Expand Down
54 changes: 34 additions & 20 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import {
enqueuePendingPassiveProfilerEffect,
restorePendingUpdaters,
addTransitionStartCallbackToPendingTransition,
addTransitionProgressCallbackToPendingTransition,
addTransitionCompleteCallbackToPendingTransition,
addMarkerCompleteCallbackToPendingTransition,
setIsRunningInsertionEffect,
Expand Down Expand Up @@ -1110,20 +1111,32 @@ function commitTransitionProgress(offscreenFiber: Fiber) {
// The suspense boundaries was just hidden. Add the boundary
// to the pending boundary set if it's there
if (pendingMarkers !== null) {
pendingMarkers.forEach(pendingBoundaries => {
pendingBoundaries.set(offscreenInstance, {
name,
});
pendingMarkers.forEach(markerInstance => {
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
if (
pendingBoundaries !== null &&
!pendingBoundaries.has(offscreenInstance)
) {
pendingBoundaries.set(offscreenInstance, {
name,
});
markerInstance.hasUpdate = true;
}
});
}
} else if (wasHidden && !isHidden) {
// The suspense boundary went from hidden to visible. Remove
// the boundary from the pending suspense boundaries set
// if it's there
if (pendingMarkers !== null) {
pendingMarkers.forEach(pendingBoundaries => {
if (pendingBoundaries.has(offscreenInstance)) {
pendingMarkers.forEach(markerInstance => {
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
if (
pendingBoundaries !== null &&
pendingBoundaries.has(offscreenInstance)
) {
pendingBoundaries.delete(offscreenInstance);
markerInstance.hasUpdate = true;
}
});
}
Expand Down Expand Up @@ -2822,17 +2835,20 @@ function commitPassiveMountOnFiber(
clearTransitionsForLanes(finishedRoot, committedLanes);
}

incompleteTransitions.forEach(
({pendingSuspenseBoundaries}, transition) => {
if (
pendingSuspenseBoundaries === null ||
pendingSuspenseBoundaries.size === 0
) {
addTransitionCompleteCallbackToPendingTransition(transition);
incompleteTransitions.delete(transition);
}
},
);
incompleteTransitions.forEach((markerInstance, transition) => {
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
if (markerInstance.hasUpdate) {
addTransitionProgressCallbackToPendingTransition({
transition,
pending: pendingBoundaries || [],
});
markerInstance.hasUpdate = false;
}
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
addTransitionCompleteCallbackToPendingTransition(transition);
incompleteTransitions.delete(transition);
}
});

clearTransitionsForLanes(finishedRoot, committedLanes);
}
Expand Down Expand Up @@ -2909,9 +2925,7 @@ function commitPassiveMountOnFiber(
instance.pendingMarkers = new Set();
}

instance.pendingMarkers.add(
markerInstance.pendingSuspenseBoundaries,
);
instance.pendingMarkers.add(markerInstance);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export type MarkerTransition = {
name: string,
};

export type TransitionProgress = {
transition: Transition,
pending: PendingSuspenseBoundaries,
};

export type PendingTransitionCallbacks = {
transitionStart: Array<Transition> | null,
transitionProgress: Array<TransitionProgress> | null,
transitionComplete: Array<Transition> | null,
markerComplete: Array<MarkerTransition> | null,
};
Expand All @@ -42,6 +48,7 @@ export type BatchConfigTransition = {
export type TracingMarkerInstance = {|
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
transitions: Set<Transition> | null,
hasUpdate: boolean,
|};

export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;
Expand Down Expand Up @@ -76,6 +83,19 @@ export function processTransitionCallbacks(
});
}

const transitionProgress = pendingTransitions.transitionProgress;
const onTransitionProgress = callbacks.onTransitionProgress;
if (onTransitionProgress != null && transitionProgress !== null) {
transitionProgress.forEach(({transition, pending}) => {
onTransitionProgress(
transition.name,
transition.startTime,
endTime,
Array.from(pending.values()),
);
});
}

const transitionComplete = pendingTransitions.transitionComplete;
if (transitionComplete !== null) {
transitionComplete.forEach(transition => {
Expand Down Expand Up @@ -117,10 +137,12 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
if (transitions !== null) {
transitions.forEach(transition => {
if (!root.incompleteTransitions.has(transition)) {
root.incompleteTransitions.set(transition, {
const markerInstance: TracingMarkerInstance = {
transitions: new Set([transition]),
pendingSuspenseBoundaries: null,
});
hasUpdate: true,
};
root.incompleteTransitions.set(transition, markerInstance);
}
});
}
Expand Down
25 changes: 25 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {EventPriority} from './ReactEventPriorities.old';
import type {
PendingTransitionCallbacks,
MarkerTransition,
TransitionProgress,
Transition,
} from './ReactFiberTracingMarkerComponent.old';

Expand Down Expand Up @@ -349,6 +350,7 @@ export function addTransitionStartCallbackToPendingTransition(
if (currentPendingTransitionCallbacks === null) {
currentPendingTransitionCallbacks = {
transitionStart: [],
transitionProgress: null,
transitionComplete: null,
markerComplete: null,
};
Expand All @@ -369,6 +371,7 @@ export function addMarkerCompleteCallbackToPendingTransition(
if (currentPendingTransitionCallbacks === null) {
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionProgress: null,
transitionComplete: null,
markerComplete: [],
};
Expand All @@ -382,13 +385,35 @@ export function addMarkerCompleteCallbackToPendingTransition(
}
}

export function addTransitionProgressCallbackToPendingTransition(
transition: TransitionProgress,
) {
if (enableTransitionTracing) {
if (currentPendingTransitionCallbacks === null) {
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionProgress: [],
transitionComplete: null,
markerComplete: null,
};
}

if (currentPendingTransitionCallbacks.transitionProgress === null) {
currentPendingTransitionCallbacks.transitionProgress = [];
}

currentPendingTransitionCallbacks.transitionProgress.push(transition);
}
}

export function addTransitionCompleteCallbackToPendingTransition(
transition: Transition,
) {
if (enableTransitionTracing) {
if (currentPendingTransitionCallbacks === null) {
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionProgress: null,
transitionComplete: [],
markerComplete: null,
};
Expand Down

0 comments on commit ffbfaa0

Please sign in to comment.