Skip to content

Commit

Permalink
Remove last schedulePassiveEffectCallback call (#20042)
Browse files Browse the repository at this point in the history
Now there's only a single place where the passive effect callback
is scheduled.
  • Loading branch information
acdlite committed Oct 16, 2020
1 parent e9f5ad2 commit 0dd809b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
6 changes: 0 additions & 6 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import {
Update,
Callback,
LayoutMask,
PassiveMask,
Ref,
} from './ReactFiberFlags';
import getComponentName from 'shared/getComponentName';
Expand Down Expand Up @@ -125,7 +124,6 @@ import {
captureCommitPhaseError,
resolveRetryWakeable,
markCommitTimeOfFallback,
schedulePassiveEffectCallback,
} from './ReactFiberWorkLoop.new';
import {
NoFlags as NoHookEffect,
Expand Down Expand Up @@ -599,10 +597,6 @@ function recursivelyCommitLayoutEffects(
finishedWork,
);
}

if ((finishedWork.subtreeFlags & PassiveMask) !== NoFlags) {
schedulePassiveEffectCallback();
}
break;
}
case ClassComponent: {
Expand Down
56 changes: 18 additions & 38 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ let hasUncaughtError = false;
let firstUncaughtError = null;
let legacyErrorBoundariesThatAlreadyFailed: Set<mixed> | null = null;

let rootDoesHavePassiveEffects: boolean = false;
let rootWithPendingPassiveEffects: FiberRoot | null = null;
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
let pendingPassiveEffectsLanes: Lanes = NoLanes;
Expand Down Expand Up @@ -1865,6 +1864,22 @@ function commitRootImpl(root, renderPriorityLevel) {
// times out.
}

// If there are pending passive effects, schedule a callback to process them.
// Do this as early as possible, so it is queued before anything else that
// might get scheduled in the commit phase. (See #16714.)
const rootDoesHavePassiveEffects =
(finishedWork.subtreeFlags & PassiveMask) !== NoFlags ||
(finishedWork.flags & PassiveMask) !== NoFlags;
if (rootDoesHavePassiveEffects) {
rootWithPendingPassiveEffects = root;
pendingPassiveEffectsLanes = lanes;
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
scheduleCallback(NormalSchedulerPriority, () => {
flushPassiveEffects();
return null;
});
}

// Check if there are any effects in the whole tree.
// TODO: This is left over from the effect list implementation, where we had
// to check for the existence of `firstEffect` to satsify Flow. I think the
Expand All @@ -1880,20 +1895,6 @@ function commitRootImpl(root, renderPriorityLevel) {
NoFlags;

if (subtreeHasEffects || rootHasEffect) {
// If there are pending passive effects, schedule a callback to process them.
if (
(finishedWork.subtreeFlags & PassiveMask) !== NoFlags ||
(finishedWork.flags & PassiveMask) !== NoFlags
) {
if (!rootDoesHavePassiveEffects) {
rootDoesHavePassiveEffects = true;
scheduleCallback(NormalSchedulerPriority, () => {
flushPassiveEffects();
return null;
});
}
}

let previousLanePriority;
if (decoupleUpdatePriorityFromScheduler) {
previousLanePriority = getCurrentUpdateLanePriority();
Expand Down Expand Up @@ -2010,17 +2011,6 @@ function commitRootImpl(root, renderPriorityLevel) {
}
}

const rootDidHavePassiveEffects = rootDoesHavePassiveEffects;

if (rootDoesHavePassiveEffects) {
// This commit has passive effects. Stash a reference to them. But don't
// schedule a callback until after flushing layout work.
rootDoesHavePassiveEffects = false;
rootWithPendingPassiveEffects = root;
pendingPassiveEffectsLanes = lanes;
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
}

// Read this again, since an effect might have updated it
remainingLanes = root.pendingLanes;

Expand All @@ -2047,13 +2037,13 @@ function commitRootImpl(root, renderPriorityLevel) {
}

if (__DEV__ && enableDoubleInvokingEffects) {
if (!rootDidHavePassiveEffects) {
if (!rootDoesHavePassiveEffects) {
commitDoubleInvokeEffectsInDEV(root.current, false);
}
}

if (enableSchedulerTracing) {
if (!rootDidHavePassiveEffects) {
if (!rootDoesHavePassiveEffects) {
// If there are no passive effects, then we can complete the pending interactions.
// Otherwise, we'll wait until after the passive effects are flushed.
// Wait to do this until after remaining work has been scheduled,
Expand Down Expand Up @@ -2356,16 +2346,6 @@ function commitMutationEffectsDeletions(
}
}

export function schedulePassiveEffectCallback() {
if (!rootDoesHavePassiveEffects) {
rootDoesHavePassiveEffects = true;
scheduleCallback(NormalSchedulerPriority, () => {
flushPassiveEffects();
return null;
});
}
}

export function flushPassiveEffects(): boolean {
// Returns whether passive effects were flushed.
if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {
Expand Down

0 comments on commit 0dd809b

Please sign in to comment.