From fe3c059569298fdcae037b8d207ed6553367a77d Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 10 Sep 2020 15:14:30 -0500 Subject: [PATCH] Don't visit passive effects during layout phase Removes the `Update` flag when scheduling a passive effect for `useEffect`. The `Passive` flag alone is sufficient. This doesn't affect any behavior, but does optimize the performance of the commit phase. --- packages/react-reconciler/src/ReactFiberHooks.new.js | 12 +++--------- .../react-reconciler/src/ReactFiberWorkLoop.new.js | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index ab7b58715a554..ea7d5a983d242 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -1241,7 +1241,7 @@ function mountEffect( } } return mountEffectImpl( - UpdateEffect | PassiveEffect | PassiveStaticEffect, + PassiveEffect | PassiveStaticEffect, HookPassive, create, deps, @@ -1258,12 +1258,7 @@ function updateEffect( warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber); } } - return updateEffectImpl( - UpdateEffect | PassiveEffect, - HookPassive, - create, - deps, - ); + return updateEffectImpl(PassiveEffect, HookPassive, create, deps); } function mountLayoutEffect( @@ -1615,8 +1610,7 @@ function mountOpaqueIdentifier(): OpaqueIDType | void { const setId = mountState(id)[1]; if ((currentlyRenderingFiber.mode & BlockingMode) === NoMode) { - currentlyRenderingFiber.flags |= - UpdateEffect | PassiveEffect | PassiveStaticEffect; + currentlyRenderingFiber.flags |= PassiveEffect | PassiveStaticEffect; pushEffect( HookHasEffect | HookPassive, () => { diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index eb835a685078b..0f8766ce4ad43 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -2623,7 +2623,7 @@ function flushPassiveMountEffects(firstChild: Fiber): void { flushPassiveMountEffects(fiber.child); } - if ((fiber.flags & Update) !== NoFlags) { + if ((fiber.flags & Passive) !== NoFlags) { setCurrentDebugFiberInDEV(fiber); commitPassiveEffectOnFiber(fiber); resetCurrentDebugFiberInDEV();