Skip to content

Commit ab5b379

Browse files
committed
Re-land "Clean up host pointers in level 2 of clean-up flag (#21112)"
This re-lands commit 8ed0c85.
1 parent fd907c1 commit ab5b379

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,18 @@ function detachFiberAfterEffects(fiber: Fiber) {
13821382
fiber.deletions = null;
13831383
fiber.sibling = null;
13841384

1385+
// The `stateNode` is cyclical because on host nodes it points to the host
1386+
// tree, which has its own pointers to children, parents, and siblings.
1387+
// The other host nodes also point back to fibers, so we should detach that
1388+
// one, too.
1389+
if (fiber.tag === HostComponent) {
1390+
const hostInstance: Instance = fiber.stateNode;
1391+
if (hostInstance !== null) {
1392+
detachDeletedInstance(hostInstance);
1393+
}
1394+
}
1395+
fiber.stateNode = null;
1396+
13851397
// I'm intentionally not clearing the `return` field in this level. We
13861398
// already disconnect the `return` pointer at the root of the deleted
13871399
// subtree (in `detachFiberMutation`). Besides, `return` by itself is not
@@ -1400,15 +1412,6 @@ function detachFiberAfterEffects(fiber: Fiber) {
14001412
// The purpose of this branch is to be super aggressive so we can measure
14011413
// if there's any difference in memory impact. If there is, that could
14021414
// indicate a React leak we don't know about.
1403-
1404-
// For host components, disconnect host instance -> fiber pointer.
1405-
if (fiber.tag === HostComponent) {
1406-
const hostInstance: Instance = fiber.stateNode;
1407-
if (hostInstance !== null) {
1408-
detachDeletedInstance(hostInstance);
1409-
}
1410-
}
1411-
14121415
fiber.return = null;
14131416
fiber.dependencies = null;
14141417
fiber.memoizedProps = null;

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,18 @@ function detachFiberAfterEffects(fiber: Fiber) {
13821382
fiber.deletions = null;
13831383
fiber.sibling = null;
13841384

1385+
// The `stateNode` is cyclical because on host nodes it points to the host
1386+
// tree, which has its own pointers to children, parents, and siblings.
1387+
// The other host nodes also point back to fibers, so we should detach that
1388+
// one, too.
1389+
if (fiber.tag === HostComponent) {
1390+
const hostInstance: Instance = fiber.stateNode;
1391+
if (hostInstance !== null) {
1392+
detachDeletedInstance(hostInstance);
1393+
}
1394+
}
1395+
fiber.stateNode = null;
1396+
13851397
// I'm intentionally not clearing the `return` field in this level. We
13861398
// already disconnect the `return` pointer at the root of the deleted
13871399
// subtree (in `detachFiberMutation`). Besides, `return` by itself is not
@@ -1400,15 +1412,6 @@ function detachFiberAfterEffects(fiber: Fiber) {
14001412
// The purpose of this branch is to be super aggressive so we can measure
14011413
// if there's any difference in memory impact. If there is, that could
14021414
// indicate a React leak we don't know about.
1403-
1404-
// For host components, disconnect host instance -> fiber pointer.
1405-
if (fiber.tag === HostComponent) {
1406-
const hostInstance: Instance = fiber.stateNode;
1407-
if (hostInstance !== null) {
1408-
detachDeletedInstance(hostInstance);
1409-
}
1410-
}
1411-
14121415
fiber.return = null;
14131416
fiber.dependencies = null;
14141417
fiber.memoizedProps = null;

0 commit comments

Comments
 (0)