Skip to content

Commit

Permalink
Don't visit passive effects during layout phase
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Sep 10, 2020
1 parent ad8a0a8 commit fe3c059
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ function mountEffect(
}
}
return mountEffectImpl(
UpdateEffect | PassiveEffect | PassiveStaticEffect,
PassiveEffect | PassiveStaticEffect,
HookPassive,
create,
deps,
Expand All @@ -1258,12 +1258,7 @@ function updateEffect(
warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber);
}
}
return updateEffectImpl(
UpdateEffect | PassiveEffect,
HookPassive,
create,
deps,
);
return updateEffectImpl(PassiveEffect, HookPassive, create, deps);
}

function mountLayoutEffect(
Expand Down Expand Up @@ -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,
() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fe3c059

Please sign in to comment.