Skip to content

Commit 43b1f74

Browse files
committed
Alternate fix for #14198
This doesn't rely on checking the tag. When the alternate of a parent is missing, it assumes it's a fragment indirection and moves onto the next parent fiber.
1 parent 41aa345 commit 43b1f74

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

packages/react-reconciler/src/ReactFiberTreeReflection.js

+18-26
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
HostRoot,
2222
HostPortal,
2323
HostText,
24-
Fragment,
25-
SuspenseComponent,
2624
} from 'shared/ReactWorkTags';
2725
import {NoEffect, Placement} from 'shared/ReactSideEffectTags';
2826

@@ -115,33 +113,27 @@ export function findCurrentFiberUsingSlowPath(fiber: Fiber): Fiber | null {
115113
// If we have two possible branches, we'll walk backwards up to the root
116114
// to see what path the root points to. On the way we may hit one of the
117115
// special cases and we'll deal with them.
118-
let a = fiber;
119-
let b = alternate;
116+
let a: Fiber = fiber;
117+
let b: Fiber = alternate;
120118
while (true) {
121119
let parentA = a.return;
122-
let parentB = parentA ? parentA.alternate : null;
123-
if (!parentA || !parentB) {
124-
// We're either at the root, or we're in a special Fragment
125-
// with no alternate, which is how Suspense (un)hiding works.
126-
let maybeSuspenseFragment = parentA || parentB;
127-
if (maybeSuspenseFragment && maybeSuspenseFragment.tag === Fragment) {
128-
const maybeSuspense = maybeSuspenseFragment.return;
129-
if (
130-
maybeSuspense &&
131-
maybeSuspense.tag === SuspenseComponent &&
132-
// If state isn't null, it timed out and we have two Fragment children.
133-
maybeSuspense.memoizedState !== null
134-
) {
135-
parentA = maybeSuspense;
136-
parentB = maybeSuspense;
137-
a = maybeSuspenseFragment;
138-
b = maybeSuspenseFragment;
139-
} else {
140-
break;
141-
}
142-
} else {
143-
break;
120+
if (parentA === null) {
121+
// We're at the root.
122+
break;
123+
}
124+
let parentB = parentA.alternate;
125+
if (parentB === null) {
126+
// There is no alternate. This is an unusual case. Currently, it only
127+
// happens when a Suspense component is hidden. An extra fragment fiber
128+
// is inserted in between the Suspense fiber and its children. Skip
129+
// over this extra fragment fiber and proceed to the next parent.
130+
const nextParent = parentA.return;
131+
if (nextParent !== null) {
132+
a = b = nextParent;
133+
continue;
144134
}
135+
// If there's no parent, we're at the root.
136+
break;
145137
}
146138

147139
// If both copies of the parent fiber point to the same child, we can

0 commit comments

Comments
 (0)