Skip to content

Commit 84558c6

Browse files
authored
Don't visit passive effects during layout phase (#19809)
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.
1 parent ad8a0a8 commit 84558c6

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

packages/react-reconciler/src/ReactFiberHooks.new.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ function mountEffect(
12411241
}
12421242
}
12431243
return mountEffectImpl(
1244-
UpdateEffect | PassiveEffect | PassiveStaticEffect,
1244+
PassiveEffect | PassiveStaticEffect,
12451245
HookPassive,
12461246
create,
12471247
deps,
@@ -1258,12 +1258,7 @@ function updateEffect(
12581258
warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber);
12591259
}
12601260
}
1261-
return updateEffectImpl(
1262-
UpdateEffect | PassiveEffect,
1263-
HookPassive,
1264-
create,
1265-
deps,
1266-
);
1261+
return updateEffectImpl(PassiveEffect, HookPassive, create, deps);
12671262
}
12681263

12691264
function mountLayoutEffect(
@@ -1615,8 +1610,7 @@ function mountOpaqueIdentifier(): OpaqueIDType | void {
16151610
const setId = mountState(id)[1];
16161611

16171612
if ((currentlyRenderingFiber.mode & BlockingMode) === NoMode) {
1618-
currentlyRenderingFiber.flags |=
1619-
UpdateEffect | PassiveEffect | PassiveStaticEffect;
1613+
currentlyRenderingFiber.flags |= PassiveEffect | PassiveStaticEffect;
16201614
pushEffect(
16211615
HookHasEffect | HookPassive,
16221616
() => {

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,7 @@ function flushPassiveMountEffects(firstChild: Fiber): void {
26232623
flushPassiveMountEffects(fiber.child);
26242624
}
26252625

2626-
if ((fiber.flags & Update) !== NoFlags) {
2626+
if ((fiber.flags & Passive) !== NoFlags) {
26272627
setCurrentDebugFiberInDEV(fiber);
26282628
commitPassiveEffectOnFiber(fiber);
26292629
resetCurrentDebugFiberInDEV();

0 commit comments

Comments
 (0)