Skip to content

Commit c896cf9

Browse files
authored
Set return pointer when reusing current tree (#20212)
* Do not fix return pointers during commit phase In the commit phase, we should be able to assume that the `return` pointers in the just-completed tree are consistent. The render phase should be responsible for ensuring these are always correct. I've removed the `return` pointer assignments from the render phase traversal logic. This isn't all of them, only the ones added recently during the effects refactor. The other ones have been around longer so I'll leave those for a later clean up. This breaks a few SuspenseList tests; I'll fix in the next commit. * Set return pointer when reusing current tree We always set the return pointer on freshly cloned, work-in-progress fibers. However, we were neglecting to set them on trees that are reused from current. I fixed this in the same path of the complete phase where we reset the fiber flags. This is a code smell because it assumes the commit phase is never concurrent with the render phase. Our eventual goal is to make fibers a lock free data structure. Will address further during refactor to alternate model.
1 parent 0898660 commit c896cf9

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

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

-14
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ function iterativelyCommitBeforeMutationEffects_begin() {
463463
(fiber.subtreeFlags & BeforeMutationMask) !== NoFlags &&
464464
child !== null
465465
) {
466-
child.return = fiber;
467466
nextEffect = child;
468467
} else {
469468
iterativelyCommitBeforeMutationEffects_complete();
@@ -497,7 +496,6 @@ function iterativelyCommitBeforeMutationEffects_complete() {
497496

498497
const sibling = fiber.sibling;
499498
if (sibling !== null) {
500-
sibling.return = fiber.return;
501499
nextEffect = sibling;
502500
return;
503501
}
@@ -715,7 +713,6 @@ function iterativelyCommitMutationEffects_begin(
715713

716714
const child = fiber.child;
717715
if ((fiber.subtreeFlags & MutationMask) !== NoFlags && child !== null) {
718-
child.return = fiber;
719716
nextEffect = child;
720717
} else {
721718
iterativelyCommitMutationEffects_complete(root, renderPriorityLevel);
@@ -754,7 +751,6 @@ function iterativelyCommitMutationEffects_complete(
754751

755752
const sibling = fiber.sibling;
756753
if (sibling !== null) {
757-
sibling.return = fiber.return;
758754
nextEffect = sibling;
759755
return;
760756
}
@@ -1176,14 +1172,12 @@ function iterativelyCommitLayoutEffects_begin(
11761172
}
11771173
const sibling = finishedWork.sibling;
11781174
if (sibling !== null) {
1179-
sibling.return = finishedWork.return;
11801175
nextEffect = sibling;
11811176
} else {
11821177
nextEffect = finishedWork.return;
11831178
iterativelyCommitLayoutEffects_complete(subtreeRoot, finishedRoot);
11841179
}
11851180
} else {
1186-
firstChild.return = finishedWork;
11871181
nextEffect = firstChild;
11881182
}
11891183
} else {
@@ -1230,7 +1224,6 @@ function iterativelyCommitLayoutEffects_complete(
12301224

12311225
const sibling = fiber.sibling;
12321226
if (sibling !== null) {
1233-
sibling.return = fiber.return;
12341227
nextEffect = sibling;
12351228
return;
12361229
}
@@ -1764,14 +1757,12 @@ function iterativelyCommitPassiveMountEffects_begin(
17641757
}
17651758
const sibling = fiber.sibling;
17661759
if (sibling !== null) {
1767-
sibling.return = fiber.return;
17681760
nextEffect = sibling;
17691761
} else {
17701762
nextEffect = fiber.return;
17711763
iterativelyCommitPassiveMountEffects_complete(subtreeRoot, root);
17721764
}
17731765
} else {
1774-
firstChild.return = fiber;
17751766
nextEffect = firstChild;
17761767
}
17771768
} else {
@@ -1817,7 +1808,6 @@ function iterativelyCommitPassiveMountEffects_complete(
18171808

18181809
const sibling = fiber.sibling;
18191810
if (sibling !== null) {
1820-
sibling.return = fiber.return;
18211811
nextEffect = sibling;
18221812
return;
18231813
}
@@ -1896,7 +1886,6 @@ function iterativelyCommitPassiveUnmountEffects_begin() {
18961886
}
18971887

18981888
if ((fiber.subtreeFlags & PassiveMask) !== NoFlags && child !== null) {
1899-
child.return = fiber;
19001889
nextEffect = child;
19011890
} else {
19021891
iterativelyCommitPassiveUnmountEffects_complete();
@@ -1915,7 +1904,6 @@ function iterativelyCommitPassiveUnmountEffects_complete() {
19151904

19161905
const sibling = fiber.sibling;
19171906
if (sibling !== null) {
1918-
sibling.return = fiber.return;
19191907
nextEffect = sibling;
19201908
return;
19211909
}
@@ -1953,7 +1941,6 @@ function iterativelyCommitPassiveUnmountEffectsInsideOfDeletedTree_begin(
19531941
const fiber = nextEffect;
19541942
const child = fiber.child;
19551943
if ((fiber.subtreeFlags & PassiveStatic) !== NoFlags && child !== null) {
1956-
child.return = fiber;
19571944
nextEffect = child;
19581945
} else {
19591946
iterativelyCommitPassiveUnmountEffectsInsideOfDeletedTree_complete(
@@ -1981,7 +1968,6 @@ function iterativelyCommitPassiveUnmountEffectsInsideOfDeletedTree_complete(
19811968

19821969
const sibling = fiber.sibling;
19831970
if (sibling !== null) {
1984-
sibling.return = fiber.return;
19851971
nextEffect = sibling;
19861972
return;
19871973
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ function bubbleProperties(completedWork: Fiber) {
738738
subtreeFlags |= child.subtreeFlags;
739739
subtreeFlags |= child.flags;
740740

741+
// Update the return pointer so the tree is consistent. This is a code
742+
// smell because it assumes the commit phase is never concurrent with
743+
// the render phase. Will address during refactor to alternate model.
744+
child.return = completedWork;
745+
741746
child = child.sibling;
742747
}
743748
}
@@ -784,6 +789,11 @@ function bubbleProperties(completedWork: Fiber) {
784789
subtreeFlags |= child.subtreeFlags & StaticMask;
785790
subtreeFlags |= child.flags & StaticMask;
786791

792+
// Update the return pointer so the tree is consistent. This is a code
793+
// smell because it assumes the commit phase is never concurrent with
794+
// the render phase. Will address during refactor to alternate model.
795+
child.return = completedWork;
796+
787797
child = child.sibling;
788798
}
789799
}

0 commit comments

Comments
 (0)