Skip to content

Commit

Permalink
old
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Jul 8, 2022
1 parent 1c99766 commit 2940bd5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
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 @@ -978,6 +978,7 @@ function updateTracingMarkerComponent(
const markerInstance: TracingMarkerInstance = {
transitions: new Set(currentTransitions),
pendingSuspenseBoundaries: new Map(),
name: workInProgress.pendingProps.name,
};
workInProgress.stateNode = markerInstance;
}
Expand Down
39 changes: 29 additions & 10 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import {
addTransitionStartCallbackToPendingTransition,
addTransitionProgressCallbackToPendingTransition,
addTransitionCompleteCallbackToPendingTransition,
addMarkerProgressCallbackToPendingTransition,
addMarkerCompleteCallbackToPendingTransition,
setIsRunningInsertionEffect,
} from './ReactFiberWorkLoop.old';
Expand Down Expand Up @@ -1122,20 +1123,29 @@ function commitTransitionProgress(offscreenFiber: Fiber) {
if (pendingMarkers !== null) {
pendingMarkers.forEach(markerInstance => {
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
const transitions = markerInstance.transitions;
if (
pendingBoundaries !== null &&
!pendingBoundaries.has(offscreenInstance)
) {
pendingBoundaries.set(offscreenInstance, {
name,
});
if (markerInstance.transitions !== null) {
markerInstance.transitions.forEach(transition => {
addTransitionProgressCallbackToPendingTransition(
transition,
if (transitions !== null) {
if (markerInstance.name) {
addMarkerProgressCallbackToPendingTransition(
markerInstance.name,
transitions,
pendingBoundaries,
);
});
} else {
transitions.forEach(transition => {
addTransitionProgressCallbackToPendingTransition(
transition,
pendingBoundaries,
);
});
}
}
}
});
Expand All @@ -1147,18 +1157,27 @@ function commitTransitionProgress(offscreenFiber: Fiber) {
if (pendingMarkers !== null) {
pendingMarkers.forEach(markerInstance => {
const pendingBoundaries = markerInstance.pendingSuspenseBoundaries;
const transitions = markerInstance.transitions;
if (
pendingBoundaries !== null &&
pendingBoundaries.has(offscreenInstance)
) {
pendingBoundaries.delete(offscreenInstance);
if (markerInstance.transitions !== null) {
markerInstance.transitions.forEach(transition => {
addTransitionProgressCallbackToPendingTransition(
transition,
if (transitions !== null) {
if (markerInstance.name) {
addMarkerProgressCallbackToPendingTransition(
markerInstance.name,
transitions,
pendingBoundaries,
);
});
} else {
transitions.forEach(transition => {
addTransitionProgressCallbackToPendingTransition(
transition,
pendingBoundaries,
);
});
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type PendingTransitionCallbacks = {
transitionStart: Array<Transition> | null,
transitionProgress: Map<Transition, PendingSuspenseBoundaries> | null,
transitionComplete: Array<Transition> | null,
markerProgress: Map<string, TracingMarkerInstance> | null,
markerComplete: Array<MarkerTransition> | null,
};

Expand All @@ -43,6 +44,7 @@ export type BatchConfigTransition = {
export type TracingMarkerInstance = {|
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
transitions: Set<Transition> | null,
name?: string,
|};

export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;
Expand All @@ -63,6 +65,28 @@ export function processTransitionCallbacks(
});
}

const markerProgress = pendingTransitions.markerProgress;
const onMarkerProgress = callbacks.onMarkerProgress;
if (onMarkerProgress != null && markerProgress !== null) {
markerProgress.forEach((markerInstance, markerName) => {
if (markerInstance.transitions !== null) {
const pending =
markerInstance.pendingSuspenseBoundaries !== null
? Array.from(markerInstance.pendingSuspenseBoundaries.values())
: [];
markerInstance.transitions.forEach(transition => {
onMarkerProgress(
transition.name,
markerName,
transition.startTime,
endTime,
pending,
);
});
}
});
}

const markerComplete = pendingTransitions.markerComplete;
if (markerComplete !== null) {
markerComplete.forEach(marker => {
Expand Down
31 changes: 31 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export function addTransitionStartCallbackToPendingTransition(
transitionStart: [],
transitionProgress: null,
transitionComplete: null,
markerProgress: null,
markerComplete: null,
};
}
Expand All @@ -354,6 +355,33 @@ export function addTransitionStartCallbackToPendingTransition(
}
}

export function addMarkerProgressCallbackToPendingTransition(
markerName: string,
transitions: Set<Transition>,
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
) {
if (enableTransitionTracing) {
if (currentPendingTransitionCallbacks === null) {
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionProgress: null,
transitionComplete: null,
markerProgress: new Map(),
markerComplete: null,
};
}

if (currentPendingTransitionCallbacks.markerProgress === null) {
currentPendingTransitionCallbacks.markerProgress = new Map();
}

currentPendingTransitionCallbacks.markerProgress.set(markerName, {
pendingSuspenseBoundaries,
transitions,
});
}
}

export function addMarkerCompleteCallbackToPendingTransition(
transition: MarkerTransition,
) {
Expand All @@ -363,6 +391,7 @@ export function addMarkerCompleteCallbackToPendingTransition(
transitionStart: null,
transitionProgress: null,
transitionComplete: null,
markerProgress: null,
markerComplete: [],
};
}
Expand All @@ -385,6 +414,7 @@ export function addTransitionProgressCallbackToPendingTransition(
transitionStart: null,
transitionProgress: new Map(),
transitionComplete: null,
markerProgress: null,
markerComplete: null,
};
}
Expand All @@ -409,6 +439,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
transitionStart: null,
transitionProgress: null,
transitionComplete: [],
markerProgress: null,
markerComplete: null,
};
}
Expand Down

0 comments on commit 2940bd5

Please sign in to comment.