Skip to content

Commit 42f8426

Browse files
author
Brian Vaughn
committed
Removed the temporary isDeletion hack
1 parent aa06ec4 commit 42f8426

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
Placement,
6969
Snapshot,
7070
Update,
71+
Passive,
7172
PassiveUnmountPendingDev,
7273
} from './ReactSideEffectTags';
7374
import getComponentName from 'shared/getComponentName';
@@ -879,6 +880,29 @@ function commitUnmount(
879880
if (destroy !== undefined) {
880881
if ((tag & HookPassive) !== NoHookEffect) {
881882
effect.tag |= HookHasEffect;
883+
884+
// subtreeTags currently bubble in resetChildLanes which doens't get called for unmounted subtrees.
885+
// So we need to bubble this up manually to the root (or to the nearest ancestor that already has it).
886+
let ancestor = current.return;
887+
while (ancestor !== null) {
888+
if (
889+
(ancestor.subtreeTag & PassiveSubtreeTag) !==
890+
NoSubtreeTag
891+
) {
892+
break;
893+
}
894+
895+
ancestor.subtreeTag |= PassiveSubtreeTag;
896+
const alternate = ancestor.alternate;
897+
if (alternate !== null) {
898+
alternate.subtreeTag |= PassiveSubtreeTag;
899+
}
900+
901+
ancestor = ancestor.return;
902+
}
903+
904+
current.effectTag |= Passive;
905+
882906
if (__DEV__) {
883907
// This flag is used to avoid warning about an update to an unmounted component
884908
// if the component has a passive unmount scheduled.
@@ -889,6 +913,7 @@ function commitUnmount(
889913
alternate.effectTag |= PassiveUnmountPendingDev;
890914
}
891915
}
916+
892917
schedulePassiveEffectCallback();
893918
} else {
894919
if (

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

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ import {
132132
Snapshot,
133133
Callback,
134134
Passive,
135-
// TODO (effects) Maybe get rid of this in favor of new subtreeTag?
136135
PassiveUnmountPendingDev,
137136
Incomplete,
138137
HostEffectMask,
@@ -2181,8 +2180,6 @@ function commitRootImpl(root, renderPriorityLevel) {
21812180
return null;
21822181
});
21832182
}
2184-
} else {
2185-
// TODO (effects) Clear deletion arrays
21862183
}
21872184

21882185
// Tell Scheduler to yield at the end of the frame, so the browser has an
@@ -2216,8 +2213,6 @@ function commitRootImpl(root, renderPriorityLevel) {
22162213
rootWithPendingPassiveEffects = root;
22172214
pendingPassiveEffectsLanes = lanes;
22182215
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
2219-
} else {
2220-
// TODO (effects) Detach sibling pointers for deleted Fibers
22212216
}
22222217

22232218
// Read this again, since an effect might have updated it
@@ -2418,7 +2413,8 @@ function commitMutationEffects(
24182413
renderPriorityLevel,
24192414
);
24202415

2421-
// TODO (effects) Clear deletions array if there are no pending passive effects.
2416+
// TODO (effects) Detach sibling pointers for deleted Fibers
2417+
// TODO (effects) Clear deletion arrays
24222418
}
24232419

24242420
if (fiber.child !== null) {
@@ -2773,53 +2769,49 @@ function flushPassiveMountEffectsImpl(fiber: Fiber): void {
27732769
}
27742770
}
27752771

2776-
function flushPassiveUnmountEffects(
2777-
firstChild: Fiber,
2778-
isDeletion: boolean,
2779-
): void {
2772+
function flushPassiveUnmountEffects(firstChild: Fiber): void {
27802773
let fiber = firstChild;
27812774
while (fiber !== null) {
27822775
const deletions = fiber.deletions;
27832776
if (deletions !== null) {
27842777
for (let i = 0; i < deletions.length; i++) {
27852778
const fiberToDelete = deletions[i];
2786-
// TODO (effects) This probably won't work because effectsTag and subtreeTag won't be set
2787-
// correctly for nested Fibers; we need to traverse the whole tree then which sucks.
2788-
// We should update commitUnmount() to handle this when we call enqueuePassive blah.
2789-
// TODO (effects) This is probably a change in deletion ordering (recursing subtrees this way)
2790-
// but that presumably doesn't matter so long as we process all deletions before creations?
2791-
flushPassiveUnmountEffects(fiberToDelete, true);
2779+
// If this fiber (or anything below it) has passive effects then traverse the subtree.
2780+
const primaryEffectTag = fiberToDelete.effectTag & (Passive | Update);
2781+
const primarySubtreeTag = fiberToDelete.subtreeTag & PassiveSubtreeTag;
2782+
if (
2783+
primarySubtreeTag !== NoSubtreeTag ||
2784+
primaryEffectTag !== NoEffect
2785+
) {
2786+
flushPassiveUnmountEffects(fiberToDelete);
2787+
}
27922788
}
27932789
}
27942790

27952791
const didBailout =
27962792
fiber.alternate !== null && fiber.alternate.child === fiber.child;
2797-
if (fiber.child !== null && !didBailout) {
2798-
// TODO (effects) See above
2799-
//const primarySubtreeTag = fiber.subtreeTag & Deletion;
2800-
//if (primarySubtreeTag !== NoEffect) {
2801-
flushPassiveUnmountEffects(fiber.child, isDeletion);
2802-
//}
2803-
}
2804-
// TODO (effects) Are we traversing extra here? Maybe we won't need this check
2805-
// here once we stop over traversing.
2806-
const primarySubtreeTag =
2807-
fiber.return === null ||
2808-
(fiber.return.subtreeTag & PassiveSubtreeTag) !== NoSubtreeTag;
2809-
if (
2810-
isDeletion ||
2811-
((fiber.effectTag & Update) !== NoEffect && primarySubtreeTag)
2812-
) {
2813-
switch (fiber.tag) {
2814-
case FunctionComponent:
2815-
case ForwardRef:
2816-
case SimpleMemoComponent:
2817-
case Block: {
2818-
// TODO (effects) See above
2819-
//const primaryEffectTag = fiber.effectTag & Passive;
2820-
//if (primaryEffectTag !== NoEffect) {
2793+
if (!didBailout) {
2794+
const child = fiber.child;
2795+
if (child !== null) {
2796+
// If any children have passive effects then traverse the subtree.
2797+
// Note that this requires checking subtreeTag of the current Fiber,
2798+
// rather than the subtreeTag/effectsTag of the first child,
2799+
// since that would not cover passive effects in siblings.
2800+
const primarySubtreeTag = fiber.subtreeTag & PassiveSubtreeTag;
2801+
if (primarySubtreeTag !== NoSubtreeTag) {
2802+
flushPassiveUnmountEffects(child);
2803+
}
2804+
}
2805+
}
2806+
2807+
switch (fiber.tag) {
2808+
case FunctionComponent:
2809+
case ForwardRef:
2810+
case SimpleMemoComponent:
2811+
case Block: {
2812+
const primaryEffectTag = fiber.effectTag & (Passive | Update);
2813+
if (primaryEffectTag !== NoEffect) {
28212814
flushPassiveUnmountEffectsImpl(fiber);
2822-
//}
28232815
}
28242816
}
28252817
}
@@ -2939,7 +2931,7 @@ function flushPassiveEffectsImpl() {
29392931
// e.g. a destroy function in one component may unintentionally override a ref
29402932
// value set by a create function in another component.
29412933
// Layout effects have the same constraint.
2942-
flushPassiveUnmountEffects(root.current, false);
2934+
flushPassiveUnmountEffects(root.current);
29432935
flushPassiveMountEffects(root.current);
29442936

29452937
// TODO (effects) Detach sibling pointers for deleted Fibers

0 commit comments

Comments
 (0)