Skip to content

Commit

Permalink
move post paint logic to another module and use it in the work loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Sep 12, 2022
1 parent 52f8f7b commit aeb5c50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import {
supportsMicrotasks,
errorHydratingContainer,
scheduleMicrotask,
requestPostPaintCallback,
} from './ReactFiberHostConfig';

import {
Expand Down Expand Up @@ -261,6 +260,7 @@ import {
suspendedThenableDidResolve,
isTrackingSuspendedThenable,
} from './ReactFiberWakeable.new';
import {schedulPostPaintCallback} from './ReactPostPaintCallback';

const ceil = Math.ceil;

Expand Down Expand Up @@ -2653,7 +2653,7 @@ function commitRootImpl(
// and then call the callback via the correct end time.
const prevRootTransitionCallbacks = root.transitionCallbacks;
if (prevRootTransitionCallbacks !== null) {
requestPostPaintCallback(endTime => {
schedulPostPaintCallback(endTime => {
const prevPendingTransitionCallbacks = currentPendingTransitionCallbacks;
if (prevPendingTransitionCallbacks !== null) {
currentPendingTransitionCallbacks = null;
Expand Down
26 changes: 26 additions & 0 deletions packages/react-reconciler/src/ReactPostPaintCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {requestPostPaintCallback} from './ReactFiberHostConfig';

let postPaintCallbackScheduled = false;
let callbacks = [];

export function schedulPostPaintCallback(callback) {
callbacks.push(callback);
if (!postPaintCallbackScheduled) {
postPaintCallbackScheduled = true;
requestPostPaintCallback(endTime => {
for (let i = 0; i < callbacks.length; i++) {
callbacks[i](endTime);
}
postPaintCallbackScheduled = false;
callbacks = [];
});
}
}

0 comments on commit aeb5c50

Please sign in to comment.