Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0566b70

Browse files
authored
Fix fiber memory leak with runAllPassiveEffectDestroysBeforeCreates (facebook#18554)
1 parent ca1a703 commit 0566b70

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,12 +2368,15 @@ function flushPassiveEffectsImpl() {
23682368
}
23692369
}
23702370
}
2371-
} else {
2372-
// Note: This currently assumes there are no passive effects on the root fiber
2373-
// because the root is not part of its own effect list.
2374-
// This could change in the future.
2375-
let effect = root.current.firstEffect;
2376-
while (effect !== null) {
2371+
}
2372+
// Note: This currently assumes there are no passive effects on the root fiber
2373+
// because the root is not part of its own effect list.
2374+
// This could change in the future.
2375+
let effect = root.current.firstEffect;
2376+
while (effect !== null) {
2377+
// We do this work above if this flag is enabled, so we shouldn't be
2378+
// doing it here.
2379+
if (!runAllPassiveEffectDestroysBeforeCreates) {
23772380
if (__DEV__) {
23782381
setCurrentDebugFiberInDEV(effect);
23792382
invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
@@ -2391,12 +2394,12 @@ function flushPassiveEffectsImpl() {
23912394
captureCommitPhaseError(effect, error);
23922395
}
23932396
}
2394-
2395-
const nextNextEffect = effect.nextEffect;
2396-
// Remove nextEffect pointer to assist GC
2397-
effect.nextEffect = null;
2398-
effect = nextNextEffect;
23992397
}
2398+
2399+
const nextNextEffect = effect.nextEffect;
2400+
// Remove nextEffect pointer to assist GC
2401+
effect.nextEffect = null;
2402+
effect = nextNextEffect;
24002403
}
24012404

24022405
if (enableProfilerTimer && enableProfilerCommitHooks) {

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,12 +2368,15 @@ function flushPassiveEffectsImpl() {
23682368
}
23692369
}
23702370
}
2371-
} else {
2372-
// Note: This currently assumes there are no passive effects on the root fiber
2373-
// because the root is not part of its own effect list.
2374-
// This could change in the future.
2375-
let effect = root.current.firstEffect;
2376-
while (effect !== null) {
2371+
}
2372+
// Note: This currently assumes there are no passive effects on the root fiber
2373+
// because the root is not part of its own effect list.
2374+
// This could change in the future.
2375+
let effect = root.current.firstEffect;
2376+
while (effect !== null) {
2377+
// We do this work above if this flag is enabled, so we shouldn't be
2378+
// doing it here.
2379+
if (!runAllPassiveEffectDestroysBeforeCreates) {
23772380
if (__DEV__) {
23782381
setCurrentDebugFiberInDEV(effect);
23792382
invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
@@ -2391,12 +2394,12 @@ function flushPassiveEffectsImpl() {
23912394
captureCommitPhaseError(effect, error);
23922395
}
23932396
}
2394-
2395-
const nextNextEffect = effect.nextEffect;
2396-
// Remove nextEffect pointer to assist GC
2397-
effect.nextEffect = null;
2398-
effect = nextNextEffect;
23992397
}
2398+
2399+
const nextNextEffect = effect.nextEffect;
2400+
// Remove nextEffect pointer to assist GC
2401+
effect.nextEffect = null;
2402+
effect = nextNextEffect;
24002403
}
24012404

24022405
if (enableProfilerTimer && enableProfilerCommitHooks) {

0 commit comments

Comments
 (0)