Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last schedulePassiveEffectCallback call #20042

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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