Skip to content

Commit 691096c

Browse files
author
Brian Vaughn
authored
Split recent passive effects changes into 2 flags (#18030)
* 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. * deferPassiveEffectCleanupDuringUnmount is ignored unless runAllPassiveEffectDestroysBeforeCreates is true
1 parent 56d8a73 commit 691096c

12 files changed

+5400
-5101
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 7 additions & 3 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;
@@ -795,7 +796,10 @@ function commitUnmount(
795796
if (lastEffect !== null) {
796797
const firstEffect = lastEffect.next;
797798

798-
if (deferPassiveEffectCleanupDuringUnmount) {
799+
if (
800+
deferPassiveEffectCleanupDuringUnmount &&
801+
runAllPassiveEffectDestroysBeforeCreates
802+
) {
799803
let effect = firstEffect;
800804
do {
801805
const {destroy, tag} = effect;

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)