Skip to content

Commit 162a805

Browse files
author
Brian Vaughn
committed
Eagerly set Deletions effect on Fiber when adding child to deletions array
1 parent d74b606 commit 162a805

File tree

4 files changed

+12
-40
lines changed

4 files changed

+12
-40
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ function ChildReconciler(shouldTrackSideEffects) {
293293
} else {
294294
returnFiber.deletions.push(childToDelete);
295295
}
296+
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
297+
returnFiber.effectTag |= Deletion;
296298
childToDelete.nextEffect = null;
297299
childToDelete.effectTag = Deletion;
298300
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,8 @@ function updateSuspensePrimaryChildren(
20712071
} else {
20722072
workInProgress.deletions.push(currentFallbackChildFragment);
20732073
}
2074+
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
2075+
workInProgress.effectTag |= Deletion;
20742076
}
20752077

20762078
workInProgress.child = primaryChildFragment;
@@ -3052,6 +3054,8 @@ function remountFiber(
30523054
} else {
30533055
returnFiber.deletions.push(current);
30543056
}
3057+
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
3058+
returnFiber.effectTag |= Deletion;
30553059
current.nextEffect = null;
30563060
current.effectTag = Deletion;
30573061

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function deleteHydratableInstance(
130130
} else {
131131
returnFiber.deletions.push(childToDelete);
132132
}
133+
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
134+
returnFiber.effectTag |= Deletion;
133135

134136
// This might seem like it belongs on progressedFirstDeletion. However,
135137
// these children are not part of the reconciliation list of children.

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

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ let globalMostRecentFallbackTime: number = 0;
284284
const FALLBACK_THROTTLE_MS: number = 500;
285285
const DEFAULT_TIMEOUT_MS: number = 5000;
286286

287-
let nextEffect: Fiber | null = null;
288287
let hasUncaughtError = false;
289288
let firstUncaughtError = null;
290289
let legacyErrorBoundariesThatAlreadyFailed: Set<mixed> | null = null;
@@ -1788,10 +1787,8 @@ function resetChildLanes(completedWork: Fiber) {
17881787
);
17891788

17901789
subtreeTag |= child.subtreeTag;
1790+
// TODO (effects) Document why this exception is important
17911791
subtreeTag |= child.effectTag & HostEffectMask;
1792-
if (child.deletions !== null) {
1793-
subtreeTag |= Deletion;
1794-
}
17951792

17961793
if ((child.effectTag & Incomplete) !== NoEffect) {
17971794
childrenDidNotComplete = true;
@@ -1833,10 +1830,8 @@ function resetChildLanes(completedWork: Fiber) {
18331830
);
18341831

18351832
subtreeTag |= child.subtreeTag;
1833+
// TODO (effects) Document why this exception is important
18361834
subtreeTag |= child.effectTag & HostEffectMask;
1837-
if (child.deletions !== null) {
1838-
subtreeTag |= Deletion;
1839-
}
18401835

18411836
if ((child.effectTag & Incomplete) !== NoEffect) {
18421837
childrenDidNotComplete = true;
@@ -1996,8 +1991,6 @@ function commitRootImpl(root, renderPriorityLevel) {
19961991
// layout, but class component lifecycles also fire here for legacy reasons.
19971992
commitLayoutEffects(finishedWork, root, lanes);
19981993

1999-
nextEffect = null;
2000-
20011994
// Tell Scheduler to yield at the end of the frame, so the browser has an
20021995
// opportunity to paint.
20031996
requestPaint();
@@ -2030,19 +2023,7 @@ function commitRootImpl(root, renderPriorityLevel) {
20302023
pendingPassiveEffectsLanes = lanes;
20312024
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
20322025
} else {
2033-
// We are done with the effect chain at this point so let's clear the
2034-
// nextEffect pointers to assist with GC. If we have passive effects, we'll
2035-
// clear this in flushPassiveEffects.
2036-
// TODO (effects) Traverse with subtreeTag Deletion and detatch deletions array only
2037-
nextEffect = firstEffect;
2038-
while (nextEffect !== null) {
2039-
const nextNextEffect = nextEffect.nextEffect;
2040-
nextEffect.nextEffect = null;
2041-
if (nextEffect.effectTag & Deletion) {
2042-
detachFiberAfterEffects(nextEffect);
2043-
}
2044-
nextEffect = nextNextEffect;
2045-
}
2026+
// TODO (effects) Detach sibling pointers for deleted Fibers
20462027
}
20472028

20482029
// Read this again, since an effect might have updated it
@@ -2626,20 +2607,7 @@ function flushPassiveEffectsImpl() {
26262607
}
26272608
}
26282609

2629-
// Note: This currently assumes there are no passive effects on the root fiber
2630-
// because the root is not part of its own effect list.
2631-
// This could change in the future.
2632-
// TODO (effects) Traverse with subtreeTag Deletion and detatch deletions array only
2633-
let effect = root.current.firstEffect;
2634-
while (effect !== null) {
2635-
const nextNextEffect = effect.nextEffect;
2636-
// Remove nextEffect pointer to assist GC
2637-
effect.nextEffect = null;
2638-
if (effect.effectTag & Deletion) {
2639-
detachFiberAfterEffects(effect);
2640-
}
2641-
effect = nextNextEffect;
2642-
}
2610+
// TODO (effects) Detach sibling pointers for deleted Fibers
26432611

26442612
if (enableProfilerTimer && enableProfilerCommitHooks) {
26452613
const profilerEffects = pendingPassiveProfilerEffects;
@@ -3733,7 +3701,3 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
37333701
};
37343702
}
37353703
}
3736-
3737-
function detachFiberAfterEffects(fiber: Fiber): void {
3738-
fiber.sibling = null;
3739-
}

0 commit comments

Comments
 (0)