@samitouri / QOS-React-2 / commits / 0dd809bdfa

Remove last schedulePassiveEffectCallback call (#20042)

Now there's only a single place where the passive effect callback is scheduled.

Andrew Clark committed Oct 16, 2020 at 11:06 UTC 0dd809bdfad2c2d714e369bb7f0082ce3ac34f9c
2 files changed +18 -44
packages/react-reconciler/src/ReactFiberCommitWork.new.js
-6
@@ -70,7 +70,6 @@ import {
70 Update,
71 Callback,
72 LayoutMask,
73 - PassiveMask,
73 Ref,
74 } from './ReactFiberFlags';
75 import getComponentName from 'shared/getComponentName';
@@ -125,7 +124,6 @@ import {
124 captureCommitPhaseError,
125 resolveRetryWakeable,
126 markCommitTimeOfFallback,
128 - schedulePassiveEffectCallback,
127 } from './ReactFiberWorkLoop.new';
128 import {
129 NoFlags as NoHookEffect,
@@ -599,10 +597,6 @@ function recursivelyCommitLayoutEffects(
597 finishedWork,
598 );
599 }
602 -
603 - if ((finishedWork.subtreeFlags & PassiveMask) !== NoFlags) {
604 - schedulePassiveEffectCallback();
605 - }
600 break;
601 }
602 case ClassComponent: {
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+18 -38
@@ -341,7 +341,6 @@ let hasUncaughtError = false;
341 let firstUncaughtError = null;
342 let legacyErrorBoundariesThatAlreadyFailed: Set<mixed> | null = null;
343
344 -let rootDoesHavePassiveEffects: boolean = false;
344 let rootWithPendingPassiveEffects: FiberRoot | null = null;
345 let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
346 let pendingPassiveEffectsLanes: Lanes = NoLanes;
@@ -1865,6 +1864,22 @@ function commitRootImpl(root, renderPriorityLevel) {
1864 // times out.
1865 }
1866
1867 + // If there are pending passive effects, schedule a callback to process them.
1868 + // Do this as early as possible, so it is queued before anything else that
1869 + // might get scheduled in the commit phase. (See #16714.)
1870 + const rootDoesHavePassiveEffects =
1871 + (finishedWork.subtreeFlags & PassiveMask) !== NoFlags ||
1872 + (finishedWork.flags & PassiveMask) !== NoFlags;
1873 + if (rootDoesHavePassiveEffects) {
1874 + rootWithPendingPassiveEffects = root;
1875 + pendingPassiveEffectsLanes = lanes;
1876 + pendingPassiveEffectsRenderPriority = renderPriorityLevel;
1877 + scheduleCallback(NormalSchedulerPriority, () => {
1878 + flushPassiveEffects();
1879 + return null;
1880 + });
1881 + }
1882 +
1883 // Check if there are any effects in the whole tree.
1884 // TODO: This is left over from the effect list implementation, where we had
1885 // to check for the existence of `firstEffect` to satsify Flow. I think the
@@ -1880,20 +1895,6 @@ function commitRootImpl(root, renderPriorityLevel) {
1895 NoFlags;
1896
1897 if (subtreeHasEffects || rootHasEffect) {
1883 - // If there are pending passive effects, schedule a callback to process them.
1884 - if (
1885 - (finishedWork.subtreeFlags & PassiveMask) !== NoFlags ||
1886 - (finishedWork.flags & PassiveMask) !== NoFlags
1887 - ) {
1888 - if (!rootDoesHavePassiveEffects) {
1889 - rootDoesHavePassiveEffects = true;
1890 - scheduleCallback(NormalSchedulerPriority, () => {
1891 - flushPassiveEffects();
1892 - return null;
1893 - });
1894 - }
1895 - }
1896 -
1898 let previousLanePriority;
1899 if (decoupleUpdatePriorityFromScheduler) {
1900 previousLanePriority = getCurrentUpdateLanePriority();
@@ -2010,17 +2011,6 @@ function commitRootImpl(root, renderPriorityLevel) {
2011 }
2012 }
2013
2013 - const rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
2014 -
2015 - if (rootDoesHavePassiveEffects) {
2016 - // This commit has passive effects. Stash a reference to them. But don't
2017 - // schedule a callback until after flushing layout work.
2018 - rootDoesHavePassiveEffects = false;
2019 - rootWithPendingPassiveEffects = root;
2020 - pendingPassiveEffectsLanes = lanes;
2021 - pendingPassiveEffectsRenderPriority = renderPriorityLevel;
2022 - }
2023 -
2014 // Read this again, since an effect might have updated it
2015 remainingLanes = root.pendingLanes;
2016
@@ -2047,13 +2037,13 @@ function commitRootImpl(root, renderPriorityLevel) {
2037 }
2038
2039 if (__DEV__ && enableDoubleInvokingEffects) {
2050 - if (!rootDidHavePassiveEffects) {
2040 + if (!rootDoesHavePassiveEffects) {
2041 commitDoubleInvokeEffectsInDEV(root.current, false);
2042 }
2043 }
2044
2045 if (enableSchedulerTracing) {
2056 - if (!rootDidHavePassiveEffects) {
2046 + if (!rootDoesHavePassiveEffects) {
2047 // If there are no passive effects, then we can complete the pending interactions.
2048 // Otherwise, we'll wait until after the passive effects are flushed.
2049 // Wait to do this until after remaining work has been scheduled,
@@ -2356,16 +2346,6 @@ function commitMutationEffectsDeletions(
2346 }
2347 }
2348
2359 -export function schedulePassiveEffectCallback() {
2360 - if (!rootDoesHavePassiveEffects) {
2361 - rootDoesHavePassiveEffects = true;
2362 - scheduleCallback(NormalSchedulerPriority, () => {
2363 - flushPassiveEffects();
2364 - return null;
2365 - });
2366 - }
2367 -}
2368 -
2349 export function flushPassiveEffects(): boolean {
2350 // Returns whether passive effects were flushed.
2351 if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {