Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transition Tracing] onMarkerProgress #24861

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.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
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
60 changes: 39 additions & 21 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.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.new';
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this mean we don't call onTransitionProgress if the marker has a name? Is that the desired behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will call onTransitionProgress but not onMarkerProgress. This works because a marker is either a TracingMarker or a transition on the root. If it's a tracing marker we add a name, but if it's a transition on the root we don't. This way we can tell which is a tracing marker and which is a transition and add the right callback accordingly.

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 Expand Up @@ -3041,19 +3060,18 @@ function commitPassiveMountOnFiber(
// and add a start transition callback for each of them
const instance = finishedWork.stateNode;
if (
instance.pendingSuspenseBoundaries === null ||
instance.pendingSuspenseBoundaries.size === 0
instance.transitions !== null &&
(instance.pendingSuspenseBoundaries === null ||
instance.pendingSuspenseBoundaries.size === 0)
) {
if (instance.transitions !== null) {
instance.transitions.forEach(transition => {
addMarkerCompleteCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
});
instance.transitions.forEach(transition => {
addMarkerCompleteCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
});
instance.transitions = null;
instance.pendingSuspenseBoundaries = null;
}
});
instance.transitions = null;
instance.pendingSuspenseBoundaries = null;
}
}
break;
Expand Down
60 changes: 39 additions & 21 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 Expand Up @@ -3041,19 +3060,18 @@ function commitPassiveMountOnFiber(
// and add a start transition callback for each of them
const instance = finishedWork.stateNode;
if (
instance.pendingSuspenseBoundaries === null ||
instance.pendingSuspenseBoundaries.size === 0
instance.transitions !== null &&
(instance.pendingSuspenseBoundaries === null ||
instance.pendingSuspenseBoundaries.size === 0)
) {
if (instance.transitions !== null) {
instance.transitions.forEach(transition => {
addMarkerCompleteCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
});
instance.transitions.forEach(transition => {
addMarkerCompleteCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
});
instance.transitions = null;
instance.pendingSuspenseBoundaries = null;
}
});
instance.transitions = null;
instance.pendingSuspenseBoundaries = null;
}
}
break;
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
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.new.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
Loading