Skip to content

Commit

Permalink
marker progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Jul 6, 2022
1 parent 1c39429 commit 5f4bc22
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 12 deletions.
23 changes: 17 additions & 6 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import {
addTransitionStartCallbackToPendingTransition,
addTransitionProgressCallbackToPendingTransition,
addTransitionCompleteCallbackToPendingTransition,
addMarkerProgressCallbackToPendingTransition,
addMarkerCompleteCallbackToPendingTransition,
setIsRunningInsertionEffect,
} from './ReactFiberWorkLoop.new';
Expand Down Expand Up @@ -3039,17 +3040,27 @@ function commitPassiveMountOnFiber(
// Get the transitions that were initiatized during the render
// and add a start transition callback for each of them
const instance = finishedWork.stateNode;
if (instance.transitions !== null) {
if (
if (instance.transitions !== null && instance.hasUpdate) {

This comment has been minimized.

Copy link
@acdlite

acdlite Jul 8, 2022

Collaborator

This hasUpdate thing is outdated now right? Maybe this needs to be rebased?

const transitionsComplete =
instance.pendingSuspenseBoundaries === null ||
instance.pendingSuspenseBoundaries.size === 0
) {
instance.transitions.forEach(transition => {
instance.pendingSuspenseBoundaries.size === 0;

instance.transitions.forEach(transition => {
addMarkerProgressCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
pending: instance.pendingSuspenseBoundaries,
});

if (transitionsComplete) {
addMarkerCompleteCallbackToPendingTransition({
transition,
name: finishedWork.memoizedProps.name,
});
});
}
});
instance.hasUpdate = false;
if (transitionsComplete) {
instance.transitions = null;
instance.pendingSuspenseBoundaries = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type PendingTransitionCallbacks = {
transitionStart: Array<Transition> | null,
transitionProgress: Array<TransitionProgress> | null,
transitionComplete: Array<Transition> | null,
markerProgress: Array<MarkerTransitionProgress> | null,
markerComplete: Array<MarkerTransition> | null,
};

Expand Down Expand Up @@ -73,6 +74,20 @@ export function processTransitionCallbacks(
});
}

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

const markerComplete = pendingTransitions.markerComplete;
if (markerComplete !== null) {
markerComplete.forEach(marker => {
Expand Down
27 changes: 27 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {EventPriority} from './ReactEventPriorities.new';
import type {
PendingTransitionCallbacks,
MarkerTransition,
MarkerTransitionProgress,
Transition,
TransitionProgress,
} from './ReactFiberTracingMarkerComponent.new';
Expand Down Expand Up @@ -342,6 +343,7 @@ export function addTransitionStartCallbackToPendingTransition(
transitionStart: [],
transitionProgress: null,
transitionComplete: null,
markerProgress: null,
markerComplete: null,
};
}
Expand All @@ -354,6 +356,28 @@ export function addTransitionStartCallbackToPendingTransition(
}
}

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

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

currentPendingTransitionCallbacks.markerProgress.push(transition);
}
}

export function addMarkerCompleteCallbackToPendingTransition(
transition: MarkerTransition,
) {
Expand All @@ -363,6 +387,7 @@ export function addMarkerCompleteCallbackToPendingTransition(
transitionStart: null,
transitionProgress: null,
transitionComplete: null,
markerProgress: null,
markerComplete: [],
};
}
Expand All @@ -384,6 +409,7 @@ export function addTransitionProgressCallbackToPendingTransition(
transitionStart: null,
transitionProgress: [],
transitionComplete: null,
markerProgress: null,
markerComplete: null,
};
}
Expand All @@ -405,6 +431,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
transitionStart: null,
transitionProgress: null,
transitionComplete: [],
markerProgress: null,
markerComplete: null,
};
}
Expand Down
Loading

0 comments on commit 5f4bc22

Please sign in to comment.