Skip to content

Commit

Permalink
[Transition Tracing] Create/Process Marker Complete Callback (#24700)
Browse files Browse the repository at this point in the history
This PR adds code to add a marker complete callback to the queue. It also adds code to process marker complete callback.

Marker complete callbacks, in addition to the fields that transition complete callbacks need, also have a `markerName` field
  • Loading branch information
lunaruan authored Jun 13, 2022
1 parent 327e4a1 commit 7cf8dfd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export type TransitionObject = {
startTime: number,
};

export type MarkerTransitionObject = TransitionObject & {markerName: string};
export type PendingTransitionCallbacks = {
transitionStart: Array<TransitionObject> | null,
transitionComplete: Array<TransitionObject> | null,
markerComplete: Array<MarkerTransitionObject> | null,
};

export type Transition = {
Expand Down Expand Up @@ -58,6 +60,20 @@ export function processTransitionCallbacks(
});
}

const markerComplete = pendingTransitions.markerComplete;
if (markerComplete !== null) {
markerComplete.forEach(transition => {
if (callbacks.onMarkerComplete != null) {
callbacks.onMarkerComplete(
transition.transitionName,
transition.markerName,
transition.startTime,
endTime,
);
}
});
}

const transitionComplete = pendingTransitions.transitionComplete;
if (transitionComplete !== null) {
transitionComplete.forEach(transition => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export type TransitionObject = {
startTime: number,
};

export type MarkerTransitionObject = TransitionObject & {markerName: string};
export type PendingTransitionCallbacks = {
transitionStart: Array<TransitionObject> | null,
transitionComplete: Array<TransitionObject> | null,
markerComplete: Array<MarkerTransitionObject> | null,
};

export type Transition = {
Expand Down Expand Up @@ -58,6 +60,20 @@ export function processTransitionCallbacks(
});
}

const markerComplete = pendingTransitions.markerComplete;
if (markerComplete !== null) {
markerComplete.forEach(transition => {
if (callbacks.onMarkerComplete != null) {
callbacks.onMarkerComplete(
transition.transitionName,
transition.markerName,
transition.startTime,
endTime,
);
}
});
}

const transitionComplete = pendingTransitions.transitionComplete;
if (transitionComplete !== null) {
transitionComplete.forEach(transition => {
Expand Down
23 changes: 23 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {EventPriority} from './ReactEventPriorities.new';
import type {
PendingTransitionCallbacks,
TransitionObject,
MarkerTransitionObject,
Transition,
} from './ReactFiberTracingMarkerComponent.new';

Expand Down Expand Up @@ -350,6 +351,7 @@ export function addTransitionStartCallbackToPendingTransition(
currentPendingTransitionCallbacks = {
transitionStart: [],
transitionComplete: null,
markerComplete: null,
};
}

Expand All @@ -361,6 +363,26 @@ export function addTransitionStartCallbackToPendingTransition(
}
}

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

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

currentPendingTransitionCallbacks.markerComplete.push(transition);
}
}

export function addTransitionCompleteCallbackToPendingTransition(
transition: TransitionObject,
) {
Expand All @@ -369,6 +391,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionComplete: [],
markerComplete: null,
};
}

Expand Down
23 changes: 23 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,
TransitionObject,
MarkerTransitionObject,
Transition,
} from './ReactFiberTracingMarkerComponent.old';

Expand Down Expand Up @@ -349,6 +350,7 @@ export function addTransitionStartCallbackToPendingTransition(
currentPendingTransitionCallbacks = {
transitionStart: [],
transitionComplete: null,
markerComplete: null,
};
}

Expand All @@ -360,6 +362,26 @@ export function addTransitionStartCallbackToPendingTransition(
}
}

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

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

currentPendingTransitionCallbacks.markerComplete.push(transition);
}
}

export function addTransitionCompleteCallbackToPendingTransition(
transition: TransitionObject,
) {
Expand All @@ -368,6 +390,7 @@ export function addTransitionCompleteCallbackToPendingTransition(
currentPendingTransitionCallbacks = {
transitionStart: null,
transitionComplete: [],
markerComplete: null,
};
}

Expand Down

0 comments on commit 7cf8dfd

Please sign in to comment.