Skip to content

Commit c8e3f06

Browse files
committed
Remove passive logic from layout phase
Original PR: facebook#19809
1 parent 863ee09 commit c8e3f06

File tree

3 files changed

+42
-80
lines changed

3 files changed

+42
-80
lines changed

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

+1-27
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ import {
127127
captureCommitPhaseError,
128128
resolveRetryWakeable,
129129
markCommitTimeOfFallback,
130-
enqueuePendingPassiveHookEffectMount,
131-
enqueuePendingPassiveHookEffectUnmount,
132130
enqueuePendingPassiveProfilerEffect,
133131
} from './ReactFiberWorkLoop.new';
134132
import {
@@ -414,26 +412,6 @@ function commitHookEffectListMount(tag: number, finishedWork: Fiber) {
414412
}
415413
}
416414

417-
function schedulePassiveEffects(finishedWork: Fiber) {
418-
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
419-
const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
420-
if (lastEffect !== null) {
421-
const firstEffect = lastEffect.next;
422-
let effect = firstEffect;
423-
do {
424-
const {next, tag} = effect;
425-
if (
426-
(tag & HookPassive) !== NoHookEffect &&
427-
(tag & HookHasEffect) !== NoHookEffect
428-
) {
429-
enqueuePendingPassiveHookEffectUnmount(finishedWork, effect);
430-
enqueuePendingPassiveHookEffectMount(finishedWork, effect);
431-
}
432-
effect = next;
433-
} while (effect !== firstEffect);
434-
}
435-
}
436-
437415
export function commitPassiveEffectDurations(
438416
finishedRoot: FiberRoot,
439417
finishedWork: Fiber,
@@ -519,8 +497,6 @@ function commitLifeCycles(
519497
} else {
520498
commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);
521499
}
522-
523-
schedulePassiveEffects(finishedWork);
524500
return;
525501
}
526502
case ClassComponent: {
@@ -957,9 +933,7 @@ function commitUnmount(
957933
do {
958934
const {destroy, tag} = effect;
959935
if (destroy !== undefined) {
960-
if ((tag & HookPassive) !== NoHookEffect) {
961-
enqueuePendingPassiveHookEffectUnmount(current, effect);
962-
} else {
936+
if ((tag & HookLayout) !== NoHookEffect) {
963937
if (
964938
enableProfilerTimer &&
965939
enableProfilerCommitHooks &&

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

+3-8
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ function mountEffect(
13041304
}
13051305
}
13061306
return mountEffectImpl(
1307-
UpdateEffect | PassiveEffect | PassiveStaticEffect,
1307+
PassiveEffect | PassiveStaticEffect,
13081308
HookPassive,
13091309
create,
13101310
deps,
@@ -1321,12 +1321,7 @@ function updateEffect(
13211321
warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber);
13221322
}
13231323
}
1324-
return updateEffectImpl(
1325-
UpdateEffect | PassiveEffect,
1326-
HookPassive,
1327-
create,
1328-
deps,
1329-
);
1324+
return updateEffectImpl(PassiveEffect, HookPassive, create, deps);
13301325
}
13311326

13321327
function mountLayoutEffect(
@@ -1678,7 +1673,7 @@ function mountOpaqueIdentifier(): OpaqueIDType | void {
16781673
const setId = mountState(id)[1];
16791674

16801675
if ((currentlyRenderingFiber.mode & BlockingMode) === NoMode) {
1681-
currentlyRenderingFiber.flags |= UpdateEffect | PassiveEffect;
1676+
currentlyRenderingFiber.flags |= PassiveEffect;
16821677
pushEffect(
16831678
HookHasEffect | HookPassive,
16841679
() => {

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

+38-45
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {Lanes, Lane} from './ReactFiberLane';
1313
import type {ReactPriorityLevel} from './ReactInternalTypes';
1414
import type {Interaction} from 'scheduler/src/Tracing';
1515
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
16-
import type {Effect as HookEffect} from './ReactFiberHooks.new';
1716
import type {StackCursor} from './ReactFiberStack.new';
1817
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
1918

@@ -121,8 +120,16 @@ import {
121120
import {LegacyRoot} from './ReactRootTags';
122121
import {
123122
NoFlags,
124-
PerformedWork,
125123
Placement,
124+
PassiveStatic,
125+
Incomplete,
126+
HostEffectMask,
127+
Hydrating,
128+
BeforeMutationMask,
129+
MutationMask,
130+
LayoutMask,
131+
PassiveMask,
132+
PerformedWork,
126133
Update,
127134
PlacementAndUpdate,
128135
Deletion,
@@ -131,11 +138,6 @@ import {
131138
ContentReset,
132139
Snapshot,
133140
Callback,
134-
Passive,
135-
PassiveStatic,
136-
Incomplete,
137-
HostEffectMask,
138-
Hydrating,
139141
HydratingAndUpdate,
140142
StaticMask,
141143
} from './ReactFiberFlags';
@@ -1956,7 +1958,35 @@ function commitRootImpl(root, renderPriorityLevel) {
19561958
firstEffect = finishedWork.firstEffect;
19571959
}
19581960

1959-
if (firstEffect !== null) {
1961+
// If there are pending passive effects, schedule a callback to process them.
1962+
// Do this as early as possible, so it is queued before anything else that
1963+
// might get scheduled in the commit phase. (See #16714.)
1964+
if (
1965+
(finishedWork.subtreeFlags & PassiveMask) !== NoFlags ||
1966+
(finishedWork.flags & PassiveMask) !== NoFlags
1967+
) {
1968+
rootDoesHavePassiveEffects = true;
1969+
scheduleCallback(NormalSchedulerPriority, () => {
1970+
flushPassiveEffects();
1971+
return null;
1972+
});
1973+
}
1974+
1975+
// Check if there are any effects in the whole tree.
1976+
// TODO: This is left over from the effect list implementation, where we had
1977+
// to check for the existence of `firstEffect` to satsify Flow. I think the
1978+
// only other reason this optimization exists is because it affects profiling.
1979+
// Reconsider whether this is necessary.
1980+
const subtreeHasEffects =
1981+
(finishedWork.subtreeFlags &
1982+
(BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !==
1983+
NoFlags;
1984+
const rootHasEffect =
1985+
(finishedWork.flags &
1986+
(BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !==
1987+
NoFlags;
1988+
1989+
if (subtreeHasEffects || rootHasEffect) {
19601990
let previousLanePriority;
19611991
if (decoupleUpdatePriorityFromScheduler) {
19621992
previousLanePriority = getCurrentUpdateLanePriority();
@@ -2275,17 +2305,6 @@ function commitBeforeMutationEffects() {
22752305

22762306
resetCurrentDebugFiberInDEV();
22772307
}
2278-
if ((flags & Passive) !== NoFlags) {
2279-
// If there are passive effects, schedule a callback to flush at
2280-
// the earliest opportunity.
2281-
if (!rootDoesHavePassiveEffects) {
2282-
rootDoesHavePassiveEffects = true;
2283-
scheduleCallback(NormalSchedulerPriority, () => {
2284-
flushPassiveEffects();
2285-
return null;
2286-
});
2287-
}
2288-
}
22892308
nextEffect = nextEffect.nextEffect;
22902309
}
22912310
}
@@ -2485,32 +2504,6 @@ export function enqueuePendingPassiveProfilerEffect(fiber: Fiber): void {
24852504
}
24862505
}
24872506

2488-
export function enqueuePendingPassiveHookEffectMount(
2489-
fiber: Fiber,
2490-
effect: HookEffect,
2491-
): void {
2492-
if (!rootDoesHavePassiveEffects) {
2493-
rootDoesHavePassiveEffects = true;
2494-
scheduleCallback(NormalSchedulerPriority, () => {
2495-
flushPassiveEffects();
2496-
return null;
2497-
});
2498-
}
2499-
}
2500-
2501-
export function enqueuePendingPassiveHookEffectUnmount(
2502-
fiber: Fiber,
2503-
effect: HookEffect,
2504-
): void {
2505-
if (!rootDoesHavePassiveEffects) {
2506-
rootDoesHavePassiveEffects = true;
2507-
scheduleCallback(NormalSchedulerPriority, () => {
2508-
flushPassiveEffects();
2509-
return null;
2510-
});
2511-
}
2512-
}
2513-
25142507
function flushPassiveEffectsImpl() {
25152508
if (rootWithPendingPassiveEffects === null) {
25162509
return false;

0 commit comments

Comments
 (0)