From 3ce1cb5fa608cf429a1eb7de6d47b32ad1c91323 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 6 Sep 2022 16:01:36 -0700 Subject: [PATCH] old --- .../src/ReactFiberWorkLoop.old.js | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index c4caf55518a86..180b7077f93c6 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -83,6 +83,7 @@ import { supportsMicrotasks, errorHydratingContainer, scheduleMicrotask, + requestPostPaintCallback, } from './ReactFiberHostConfig'; import { @@ -360,6 +361,7 @@ export function getWorkInProgressTransitions() { } let currentPendingTransitionCallbacks: PendingTransitionCallbacks | null = null; +let currentEndTime: number | null = null; export function addTransitionStartCallbackToPendingTransition( transition: Transition, @@ -2639,6 +2641,26 @@ function commitRootImpl( markCommitStopped(); } + // if (enableTransitionTracing) { + const prevRootTransitionCallbacks = root.transitionCallbacks; + if (prevRootTransitionCallbacks !== null) { + requestPostPaintCallback(endTime => { + const prevPendingTransitionCallbacks = currentPendingTransitionCallbacks; + if (prevPendingTransitionCallbacks !== null) { + scheduleCallback(IdleSchedulerPriority, () => { + processTransitionCallbacks( + prevPendingTransitionCallbacks, + endTime, + prevRootTransitionCallbacks, + ); + }); + } else { + currentEndTime = endTime; + } + }); + } + // } + return null; } @@ -2780,28 +2802,23 @@ function flushPassiveEffectsImpl() { if (enableTransitionTracing) { const prevPendingTransitionCallbacks = currentPendingTransitionCallbacks; const prevRootTransitionCallbacks = root.transitionCallbacks; + const prevEndTime = currentEndTime; if ( prevPendingTransitionCallbacks !== null && prevRootTransitionCallbacks !== null ) { - // TODO(luna) Refactor this code into the Host Config - // TODO(luna) The end time here is not necessarily accurate - // because passive effects could be called before paint - // (synchronously) or after paint (normally). We need - // to come up with a way to get the correct end time for both cases. - // One solution is in the host config, if the passive effects - // have not yet been run, make a call to flush the passive effects - // right after paint. - const endTime = now(); currentPendingTransitionCallbacks = null; - - scheduleCallback(IdleSchedulerPriority, () => - processTransitionCallbacks( - prevPendingTransitionCallbacks, - endTime, - prevRootTransitionCallbacks, - ), - ); + currentEndTime = null; + + if (prevEndTime !== null) { + scheduleCallback(IdleSchedulerPriority, () => + processTransitionCallbacks( + prevPendingTransitionCallbacks, + prevEndTime, + prevRootTransitionCallbacks, + ), + ); + } } }