Skip to content

Commit 7fbdfd9

Browse files
author
Brian Vaughn
committed
Copied findCurrentFiberUsingSlowPath Suspense bug fix from recent PR https://github.com/facebook/react/pull/15312/files
1 parent 99f2e0d commit 7fbdfd9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/backend/renderer.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ export function attach(
11051105
// This function is copied from React and should be kept in sync:
11061106
// https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberTreeReflection.js
11071107
// It would be nice if we updated React to inject this function directly (vs just indirectly via findDOMNode).
1108+
// BEGIN copied code
11081109
function findCurrentFiberUsingSlowPath(fiber: Fiber): Fiber | null {
11091110
let alternate = fiber.alternate;
11101111
if (!alternate) {
@@ -1121,15 +1122,28 @@ export function attach(
11211122
// If we have two possible branches, we'll walk backwards up to the root
11221123
// to see what path the root points to. On the way we may hit one of the
11231124
// special cases and we'll deal with them.
1124-
let a = fiber;
1125-
let b = alternate;
1125+
let a: Fiber = fiber;
1126+
let b: Fiber = alternate;
11261127
while (true) {
11271128
let parentA = a.return;
1128-
let parentB = parentA ? parentA.alternate : null;
1129-
if (!parentA || !parentB) {
1129+
if (parentA === null) {
11301130
// We're at the root.
11311131
break;
11321132
}
1133+
let parentB = parentA.alternate;
1134+
if (parentB === null) {
1135+
// There is no alternate. This is an unusual case. Currently, it only
1136+
// happens when a Suspense component is hidden. An extra fragment fiber
1137+
// is inserted in between the Suspense fiber and its children. Skip
1138+
// over this extra fragment fiber and proceed to the next parent.
1139+
const nextParent = parentA.return;
1140+
if (nextParent !== null) {
1141+
a = b = nextParent;
1142+
continue;
1143+
}
1144+
// If there's no parent, we're at the root.
1145+
break;
1146+
}
11331147

11341148
// If both copies of the parent fiber point to the same child, we can
11351149
// assume that the child is current. This happens when we bailout on low
@@ -1234,6 +1248,7 @@ export function attach(
12341248
// Otherwise B has to be current branch.
12351249
return alternate;
12361250
}
1251+
// END copied code
12371252

12381253
function selectElement(id: number): void {
12391254
let fiber = idToFiberMap.get(id);

0 commit comments

Comments
 (0)