Skip to content

Commit f6c7e14

Browse files
committed
[cleanup] remove deletedTreeCleanUpLevel feature flag
1 parent 79c5829 commit f6c7e14

12 files changed

+130
-243
lines changed

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

Lines changed: 65 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {
4545
enableSchedulingProfiler,
4646
enableSuspenseCallback,
4747
enableScopeAPI,
48-
deletedTreeCleanUpLevel,
4948
enableUpdaterTracking,
5049
enableCache,
5150
enableTransitionTracing,
@@ -1661,74 +1660,43 @@ function detachFiberAfterEffects(fiber: Fiber) {
16611660
detachFiberAfterEffects(alternate);
16621661
}
16631662

1664-
// Note: Defensively using negation instead of < in case
1665-
// `deletedTreeCleanUpLevel` is undefined.
1666-
if (!(deletedTreeCleanUpLevel >= 2)) {
1667-
// This is the default branch (level 0).
1668-
fiber.child = null;
1669-
fiber.deletions = null;
1670-
fiber.dependencies = null;
1671-
fiber.memoizedProps = null;
1672-
fiber.memoizedState = null;
1673-
fiber.pendingProps = null;
1674-
fiber.sibling = null;
1675-
fiber.stateNode = null;
1676-
fiber.updateQueue = null;
1677-
1678-
if (__DEV__) {
1679-
fiber._debugOwner = null;
1663+
// Clear cyclical Fiber fields. This level alone is designed to roughly
1664+
// approximate the planned Fiber refactor. In that world, `setState` will be
1665+
// bound to a special "instance" object instead of a Fiber. The Instance
1666+
// object will not have any of these fields. It will only be connected to
1667+
// the fiber tree via a single link at the root. So if this level alone is
1668+
// sufficient to fix memory issues, that bodes well for our plans.
1669+
fiber.child = null;
1670+
fiber.deletions = null;
1671+
fiber.sibling = null;
1672+
1673+
// The `stateNode` is cyclical because on host nodes it points to the host
1674+
// tree, which has its own pointers to children, parents, and siblings.
1675+
// The other host nodes also point back to fibers, so we should detach that
1676+
// one, too.
1677+
if (fiber.tag === HostComponent) {
1678+
const hostInstance: Instance = fiber.stateNode;
1679+
if (hostInstance !== null) {
1680+
detachDeletedInstance(hostInstance);
16801681
}
1681-
} else {
1682-
// Clear cyclical Fiber fields. This level alone is designed to roughly
1683-
// approximate the planned Fiber refactor. In that world, `setState` will be
1684-
// bound to a special "instance" object instead of a Fiber. The Instance
1685-
// object will not have any of these fields. It will only be connected to
1686-
// the fiber tree via a single link at the root. So if this level alone is
1687-
// sufficient to fix memory issues, that bodes well for our plans.
1688-
fiber.child = null;
1689-
fiber.deletions = null;
1690-
fiber.sibling = null;
1691-
1692-
// The `stateNode` is cyclical because on host nodes it points to the host
1693-
// tree, which has its own pointers to children, parents, and siblings.
1694-
// The other host nodes also point back to fibers, so we should detach that
1695-
// one, too.
1696-
if (fiber.tag === HostComponent) {
1697-
const hostInstance: Instance = fiber.stateNode;
1698-
if (hostInstance !== null) {
1699-
detachDeletedInstance(hostInstance);
1700-
}
1701-
}
1702-
fiber.stateNode = null;
1703-
1704-
// I'm intentionally not clearing the `return` field in this level. We
1705-
// already disconnect the `return` pointer at the root of the deleted
1706-
// subtree (in `detachFiberMutation`). Besides, `return` by itself is not
1707-
// cyclical — it's only cyclical when combined with `child`, `sibling`, and
1708-
// `alternate`. But we'll clear it in the next level anyway, just in case.
1682+
}
1683+
fiber.stateNode = null;
17091684

1710-
if (__DEV__) {
1711-
fiber._debugOwner = null;
1712-
}
1713-
1714-
if (deletedTreeCleanUpLevel >= 3) {
1715-
// Theoretically, nothing in here should be necessary, because we already
1716-
// disconnected the fiber from the tree. So even if something leaks this
1717-
// particular fiber, it won't leak anything else
1718-
//
1719-
// The purpose of this branch is to be super aggressive so we can measure
1720-
// if there's any difference in memory impact. If there is, that could
1721-
// indicate a React leak we don't know about.
1722-
fiber.return = null;
1723-
fiber.dependencies = null;
1724-
fiber.memoizedProps = null;
1725-
fiber.memoizedState = null;
1726-
fiber.pendingProps = null;
1727-
fiber.stateNode = null;
1728-
// TODO: Move to `commitPassiveUnmountInsideDeletedTreeOnFiber` instead.
1729-
fiber.updateQueue = null;
1730-
}
1685+
if (__DEV__) {
1686+
fiber._debugOwner = null;
17311687
}
1688+
1689+
// Theoretically, nothing in here should be necessary, because we already
1690+
// disconnected the fiber from the tree. So even if something leaks this
1691+
// particular fiber, it won't leak anything else.
1692+
fiber.return = null;
1693+
fiber.dependencies = null;
1694+
fiber.memoizedProps = null;
1695+
fiber.memoizedState = null;
1696+
fiber.pendingProps = null;
1697+
fiber.stateNode = null;
1698+
// TODO: Move to `commitPassiveUnmountInsideDeletedTreeOnFiber` instead.
1699+
fiber.updateQueue = null;
17321700
}
17331701

17341702
function emptyPortalContainer(current: Fiber) {
@@ -3957,31 +3925,29 @@ export function commitPassiveUnmountEffects(finishedWork: Fiber): void {
39573925
}
39583926

39593927
function detachAlternateSiblings(parentFiber: Fiber) {
3960-
if (deletedTreeCleanUpLevel >= 1) {
3961-
// A fiber was deleted from this parent fiber, but it's still part of the
3962-
// previous (alternate) parent fiber's list of children. Because children
3963-
// are a linked list, an earlier sibling that's still alive will be
3964-
// connected to the deleted fiber via its `alternate`:
3965-
//
3966-
// live fiber --alternate--> previous live fiber --sibling--> deleted
3967-
// fiber
3968-
//
3969-
// We can't disconnect `alternate` on nodes that haven't been deleted yet,
3970-
// but we can disconnect the `sibling` and `child` pointers.
3971-
3972-
const previousFiber = parentFiber.alternate;
3973-
if (previousFiber !== null) {
3974-
let detachedChild = previousFiber.child;
3975-
if (detachedChild !== null) {
3976-
previousFiber.child = null;
3977-
do {
3978-
// $FlowFixMe[incompatible-use] found when upgrading Flow
3979-
const detachedSibling = detachedChild.sibling;
3980-
// $FlowFixMe[incompatible-use] found when upgrading Flow
3981-
detachedChild.sibling = null;
3982-
detachedChild = detachedSibling;
3983-
} while (detachedChild !== null);
3984-
}
3928+
// A fiber was deleted from this parent fiber, but it's still part of the
3929+
// previous (alternate) parent fiber's list of children. Because children
3930+
// are a linked list, an earlier sibling that's still alive will be
3931+
// connected to the deleted fiber via its `alternate`:
3932+
//
3933+
// live fiber --alternate--> previous live fiber --sibling--> deleted
3934+
// fiber
3935+
//
3936+
// We can't disconnect `alternate` on nodes that haven't been deleted yet,
3937+
// but we can disconnect the `sibling` and `child` pointers.
3938+
3939+
const previousFiber = parentFiber.alternate;
3940+
if (previousFiber !== null) {
3941+
let detachedChild = previousFiber.child;
3942+
if (detachedChild !== null) {
3943+
previousFiber.child = null;
3944+
do {
3945+
// $FlowFixMe[incompatible-use] found when upgrading Flow
3946+
const detachedSibling = detachedChild.sibling;
3947+
// $FlowFixMe[incompatible-use] found when upgrading Flow
3948+
detachedChild.sibling = null;
3949+
detachedChild = detachedSibling;
3950+
} while (detachedChild !== null);
39853951
}
39863952
}
39873953
}
@@ -4167,8 +4133,7 @@ function commitPassiveUnmountEffectsInsideOfDeletedTree_begin(
41674133
resetCurrentDebugFiberInDEV();
41684134

41694135
const child = fiber.child;
4170-
// TODO: Only traverse subtree if it has a PassiveStatic flag. (But, if we
4171-
// do this, still need to handle `deletedTreeCleanUpLevel` correctly.)
4136+
// TODO: Only traverse subtree if it has a PassiveStatic flag.
41724137
if (child !== null) {
41734138
child.return = fiber;
41744139
nextEffect = child;
@@ -4188,23 +4153,13 @@ function commitPassiveUnmountEffectsInsideOfDeletedTree_complete(
41884153
const sibling = fiber.sibling;
41894154
const returnFiber = fiber.return;
41904155

4191-
if (deletedTreeCleanUpLevel >= 2) {
4192-
// Recursively traverse the entire deleted tree and clean up fiber fields.
4193-
// This is more aggressive than ideal, and the long term goal is to only
4194-
// have to detach the deleted tree at the root.
4195-
detachFiberAfterEffects(fiber);
4196-
if (fiber === deletedSubtreeRoot) {
4197-
nextEffect = null;
4198-
return;
4199-
}
4200-
} else {
4201-
// This is the default branch (level 0). We do not recursively clear all
4202-
// the fiber fields. Only the root of the deleted subtree.
4203-
if (fiber === deletedSubtreeRoot) {
4204-
detachFiberAfterEffects(fiber);
4205-
nextEffect = null;
4206-
return;
4207-
}
4156+
// Recursively traverse the entire deleted tree and clean up fiber fields.
4157+
// This is more aggressive than ideal, and the long term goal is to only
4158+
// have to detach the deleted tree at the root.
4159+
detachFiberAfterEffects(fiber);
4160+
if (fiber === deletedSubtreeRoot) {
4161+
nextEffect = null;
4162+
return;
42084163
}
42094164

42104165
if (sibling !== null) {

0 commit comments

Comments
 (0)