Skip to content

Commit 6f57d62

Browse files
committed
Destroy insertion effects when deleting previously hidden subtrees
1 parent 4b877b6 commit 6f57d62

File tree

3 files changed

+505
-54
lines changed

3 files changed

+505
-54
lines changed

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,58 +2182,59 @@ function commitDeletionEffectsOnFiber(
21822182
case ForwardRef:
21832183
case MemoComponent:
21842184
case SimpleMemoComponent: {
2185-
if (!offscreenSubtreeWasHidden) {
2186-
const updateQueue: FunctionComponentUpdateQueue | null =
2187-
(deletedFiber.updateQueue: any);
2188-
if (updateQueue !== null) {
2189-
const lastEffect = updateQueue.lastEffect;
2190-
if (lastEffect !== null) {
2191-
const firstEffect = lastEffect.next;
2192-
2193-
let effect = firstEffect;
2194-
do {
2195-
const tag = effect.tag;
2196-
const inst = effect.inst;
2197-
const destroy = inst.destroy;
2198-
if (destroy !== undefined) {
2199-
if ((tag & HookInsertion) !== NoHookEffect) {
2185+
const updateQueue: FunctionComponentUpdateQueue | null =
2186+
(deletedFiber.updateQueue: any);
2187+
if (updateQueue !== null) {
2188+
const lastEffect = updateQueue.lastEffect;
2189+
if (lastEffect !== null) {
2190+
const firstEffect = lastEffect.next;
2191+
2192+
let effect = firstEffect;
2193+
do {
2194+
const tag = effect.tag;
2195+
const inst = effect.inst;
2196+
const destroy = inst.destroy;
2197+
if (destroy !== undefined) {
2198+
if ((tag & HookInsertion) !== NoHookEffect) {
2199+
inst.destroy = undefined;
2200+
safelyCallDestroy(
2201+
deletedFiber,
2202+
nearestMountedAncestor,
2203+
destroy,
2204+
);
2205+
} else if (
2206+
!offscreenSubtreeWasHidden &&
2207+
(tag & HookLayout) !== NoHookEffect
2208+
) {
2209+
if (enableSchedulingProfiler) {
2210+
markComponentLayoutEffectUnmountStarted(deletedFiber);
2211+
}
2212+
2213+
if (shouldProfile(deletedFiber)) {
2214+
startLayoutEffectTimer();
22002215
inst.destroy = undefined;
22012216
safelyCallDestroy(
22022217
deletedFiber,
22032218
nearestMountedAncestor,
22042219
destroy,
22052220
);
2206-
} else if ((tag & HookLayout) !== NoHookEffect) {
2207-
if (enableSchedulingProfiler) {
2208-
markComponentLayoutEffectUnmountStarted(deletedFiber);
2209-
}
2210-
2211-
if (shouldProfile(deletedFiber)) {
2212-
startLayoutEffectTimer();
2213-
inst.destroy = undefined;
2214-
safelyCallDestroy(
2215-
deletedFiber,
2216-
nearestMountedAncestor,
2217-
destroy,
2218-
);
2219-
recordLayoutEffectDuration(deletedFiber);
2220-
} else {
2221-
inst.destroy = undefined;
2222-
safelyCallDestroy(
2223-
deletedFiber,
2224-
nearestMountedAncestor,
2225-
destroy,
2226-
);
2227-
}
2221+
recordLayoutEffectDuration(deletedFiber);
2222+
} else {
2223+
inst.destroy = undefined;
2224+
safelyCallDestroy(
2225+
deletedFiber,
2226+
nearestMountedAncestor,
2227+
destroy,
2228+
);
2229+
}
22282230

2229-
if (enableSchedulingProfiler) {
2230-
markComponentLayoutEffectUnmountStopped();
2231-
}
2231+
if (enableSchedulingProfiler) {
2232+
markComponentLayoutEffectUnmountStopped();
22322233
}
22332234
}
2234-
effect = effect.next;
2235-
} while (effect !== firstEffect);
2236-
}
2235+
}
2236+
effect = effect.next;
2237+
} while (effect !== firstEffect);
22372238
}
22382239
}
22392240

0 commit comments

Comments
 (0)