Skip to content

Commit 15c91fc

Browse files
author
Brian Vaughn
committed
Split recent passive effects changes into 2 flags
Separate flags can now be used to opt passive effects into: 1) Deferring destroy functions on unmount to subsequent passive effects flush 2) Running all destroy functions (for all fibers) before create functions This allows us to test the less risky feature (2) separately from the more risky one.
1 parent 58b8797 commit 15c91fc

12 files changed

+5471
-5177
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
enableFundamentalAPI,
3535
enableSuspenseCallback,
3636
enableScopeAPI,
37+
runAllPassiveEffectDestroysBeforeCreates,
3738
} from 'shared/ReactFeatureFlags';
3839
import {
3940
FunctionComponent,
@@ -398,7 +399,7 @@ function commitHookEffectListMount(tag: number, finishedWork: Fiber) {
398399
}
399400

400401
function schedulePassiveEffects(finishedWork: Fiber) {
401-
if (deferPassiveEffectCleanupDuringUnmount) {
402+
if (runAllPassiveEffectDestroysBeforeCreates) {
402403
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
403404
let lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
404405
if (lastEffect !== null) {
@@ -456,7 +457,7 @@ function commitLifeCycles(
456457
// by a create function in another component during the same commit.
457458
commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);
458459

459-
if (deferPassiveEffectCleanupDuringUnmount) {
460+
if (runAllPassiveEffectDestroysBeforeCreates) {
460461
schedulePassiveEffects(finishedWork);
461462
}
462463
return;

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {Effect as HookEffect} from './ReactFiberHooks';
1818

1919
import {
2020
warnAboutDeprecatedLifecycles,
21-
deferPassiveEffectCleanupDuringUnmount,
21+
runAllPassiveEffectDestroysBeforeCreates,
2222
enableUserTimingAPI,
2323
enableSuspenseServerRenderer,
2424
replayFailedUnitOfWorkWithInvokeGuardedCallback,
@@ -2174,7 +2174,7 @@ export function enqueuePendingPassiveHookEffectMount(
21742174
fiber: Fiber,
21752175
effect: HookEffect,
21762176
): void {
2177-
if (deferPassiveEffectCleanupDuringUnmount) {
2177+
if (runAllPassiveEffectDestroysBeforeCreates) {
21782178
pendingPassiveHookEffectsMount.push(effect, fiber);
21792179
if (!rootDoesHavePassiveEffects) {
21802180
rootDoesHavePassiveEffects = true;
@@ -2190,7 +2190,7 @@ export function enqueuePendingPassiveHookEffectUnmount(
21902190
fiber: Fiber,
21912191
effect: HookEffect,
21922192
): void {
2193-
if (deferPassiveEffectCleanupDuringUnmount) {
2193+
if (runAllPassiveEffectDestroysBeforeCreates) {
21942194
pendingPassiveHookEffectsUnmount.push(effect, fiber);
21952195
if (!rootDoesHavePassiveEffects) {
21962196
rootDoesHavePassiveEffects = true;
@@ -2224,7 +2224,7 @@ function flushPassiveEffectsImpl() {
22242224
executionContext |= CommitContext;
22252225
const prevInteractions = pushInteractions(root);
22262226

2227-
if (deferPassiveEffectCleanupDuringUnmount) {
2227+
if (runAllPassiveEffectDestroysBeforeCreates) {
22282228
// It's important that ALL pending passive effect destroy functions are called
22292229
// before ANY passive effect create functions are called.
22302230
// Otherwise effects in sibling components might interfere with each other.

0 commit comments

Comments
 (0)