@@ -1105,6 +1105,7 @@ export function attach(
1105
1105
// This function is copied from React and should be kept in sync:
1106
1106
// https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberTreeReflection.js
1107
1107
// It would be nice if we updated React to inject this function directly (vs just indirectly via findDOMNode).
1108
+ // BEGIN copied code
1108
1109
function findCurrentFiberUsingSlowPath ( fiber : Fiber ) : Fiber | null {
1109
1110
let alternate = fiber . alternate ;
1110
1111
if ( ! alternate ) {
@@ -1121,15 +1122,28 @@ export function attach(
1121
1122
// If we have two possible branches, we'll walk backwards up to the root
1122
1123
// to see what path the root points to. On the way we may hit one of the
1123
1124
// 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 ;
1126
1127
while ( true ) {
1127
1128
let parentA = a . return ;
1128
- let parentB = parentA ? parentA . alternate : null ;
1129
- if ( ! parentA || ! parentB ) {
1129
+ if ( parentA === null ) {
1130
1130
// We're at the root.
1131
1131
break;
1132
1132
}
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
+ }
1133
1147
1134
1148
// If both copies of the parent fiber point to the same child, we can
1135
1149
// assume that the child is current. This happens when we bailout on low
@@ -1234,6 +1248,7 @@ export function attach(
1234
1248
// Otherwise B has to be current branch.
1235
1249
return alternate;
1236
1250
}
1251
+ // END copied code
1237
1252
1238
1253
function selectElement ( id : number ) : void {
1239
1254
let fiber = idToFiberMap . get ( id ) ;
0 commit comments