Skip to content

Commit

Permalink
old
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Sep 7, 2022
1 parent 93155c5 commit 3ce1cb5
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
supportsMicrotasks,
errorHydratingContainer,
scheduleMicrotask,
requestPostPaintCallback,
} from './ReactFiberHostConfig';

import {
Expand Down Expand Up @@ -360,6 +361,7 @@ export function getWorkInProgressTransitions() {
}

let currentPendingTransitionCallbacks: PendingTransitionCallbacks | null = null;
let currentEndTime: number | null = null;

export function addTransitionStartCallbackToPendingTransition(
transition: Transition,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
),
);
}
}
}

Expand Down

0 comments on commit 3ce1cb5

Please sign in to comment.