diff --git a/packages/react-reconciler/src/ReactFiber.old.js b/packages/react-reconciler/src/ReactFiber.old.js index 90d0d7a7ac6fa..b26509f25d139 100644 --- a/packages/react-reconciler/src/ReactFiber.old.js +++ b/packages/react-reconciler/src/ReactFiber.old.js @@ -771,6 +771,7 @@ export function createFiberFromTracingMarker( const tracingMarkerInstance: TracingMarkerInstance = { transitions: null, pendingSuspenseBoundaries: null, + hasUpdate: false, }; fiber.stateNode = tracingMarkerInstance; return fiber; diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.old.js b/packages/react-reconciler/src/ReactFiberBeginWork.old.js index a4fccc0bbd73d..ac501c2e9218b 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.old.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.old.js @@ -909,6 +909,7 @@ function updateTracingMarkerComponent( const markerInstance: TracingMarkerInstance = { transitions: new Set(currentTransitions), pendingSuspenseBoundaries: new Map(), + hasUpdate: false, }; workInProgress.stateNode = markerInstance; } diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.old.js b/packages/react-reconciler/src/ReactFiberCommitWork.old.js index eae4bc52e3585..53b352fc185a9 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.old.js @@ -138,6 +138,7 @@ import { enqueuePendingPassiveProfilerEffect, restorePendingUpdaters, addTransitionStartCallbackToPendingTransition, + addTransitionProgressCallbackToPendingTransition, addTransitionCompleteCallbackToPendingTransition, addMarkerCompleteCallbackToPendingTransition, setIsRunningInsertionEffect, @@ -1110,10 +1111,17 @@ 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) { @@ -1121,9 +1129,14 @@ function commitTransitionProgress(offscreenFiber: Fiber) { // 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; } }); } @@ -2822,6 +2835,7 @@ function commitPassiveMountOnFiber( clearTransitionsForLanes(finishedRoot, committedLanes); } +<<<<<<< HEAD incompleteTransitions.forEach( ({pendingSuspenseBoundaries}, transition) => { if ( @@ -2833,6 +2847,25 @@ function commitPassiveMountOnFiber( } }, ); +======= + 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({ + transitionName: transition.name, + startTime: transition.startTime, + }); + incompleteTransitions.delete(transition); + } + }); +>>>>>>> 1f1184300 (old) clearTransitionsForLanes(finishedRoot, committedLanes); } @@ -2900,10 +2933,25 @@ function commitPassiveMountOnFiber( if (markerTransitions !== null) { markerTransitions.forEach(transition => { if (instance.transitions === null) { +<<<<<<< HEAD instance.transitions = new Set(); } else if (instance.transitions.has(transition)) { if (markerInstance.pendingSuspenseBoundaries === null) { markerInstance.pendingSuspenseBoundaries = new Map(); +======= + // TODO: What if instance.transitions is null? + } else { + if (instance.transitions.has(transition)) { + if ( + instance.pendingMarkers === null || + markerInstance.pendingSuspenseBoundaries === null + ) { + // TODO: What if instance.pendingMarkers is null? + // TODO: What if markerInstance.pendingSuspenseBoundaries is null? + } else { + instance.pendingMarkers.add(markerInstance); + } +>>>>>>> 1f1184300 (old) } if (instance.pendingMarkers === null) { instance.pendingMarkers = new Set(); diff --git a/packages/react-reconciler/src/ReactFiberTracingMarkerComponent.old.js b/packages/react-reconciler/src/ReactFiberTracingMarkerComponent.old.js index 0aba8780968af..8629824e1b950 100644 --- a/packages/react-reconciler/src/ReactFiberTracingMarkerComponent.old.js +++ b/packages/react-reconciler/src/ReactFiberTracingMarkerComponent.old.js @@ -22,10 +22,24 @@ export type MarkerTransition = { name: string, }; +<<<<<<< HEAD export type PendingTransitionCallbacks = { transitionStart: Array | null, transitionComplete: Array | null, markerComplete: Array | null, +======= +export type TransitionProgress = { + transition: Transition, + pending: PendingSuspenseBoundaries, +}; + +export type MarkerTransitionObject = TransitionObject & {markerName: string}; +export type PendingTransitionCallbacks = { + transitionStart: Array | null, + transitionProgress: Array | null, + transitionComplete: Array | null, + markerComplete: Array | null, +>>>>>>> 1f1184300 (old) }; export type Transition = { @@ -42,6 +56,7 @@ export type BatchConfigTransition = { export type TracingMarkerInstance = {| pendingSuspenseBoundaries: PendingSuspenseBoundaries | null, transitions: Set | null, + hasUpdate: boolean, |}; export type PendingSuspenseBoundaries = Map; @@ -76,6 +91,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 => { @@ -117,10 +145,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); } }); } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 3d3a32d8c9d5d..29ff22a061523 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -17,7 +17,13 @@ import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old'; import type {EventPriority} from './ReactEventPriorities.old'; import type { PendingTransitionCallbacks, +<<<<<<< HEAD MarkerTransition, +======= + TransitionObject, + MarkerTransitionObject, + TransitionProgress, +>>>>>>> 1f1184300 (old) Transition, } from './ReactFiberTracingMarkerComponent.old'; @@ -349,6 +355,7 @@ export function addTransitionStartCallbackToPendingTransition( if (currentPendingTransitionCallbacks === null) { currentPendingTransitionCallbacks = { transitionStart: [], + transitionProgress: null, transitionComplete: null, markerComplete: null, }; @@ -369,6 +376,7 @@ export function addMarkerCompleteCallbackToPendingTransition( if (currentPendingTransitionCallbacks === null) { currentPendingTransitionCallbacks = { transitionStart: null, + transitionProgress: null, transitionComplete: null, markerComplete: [], }; @@ -382,6 +390,27 @@ 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, ) { @@ -389,6 +418,7 @@ export function addTransitionCompleteCallbackToPendingTransition( if (currentPendingTransitionCallbacks === null) { currentPendingTransitionCallbacks = { transitionStart: null, + transitionProgress: null, transitionComplete: [], markerComplete: null, };