Skip to content

Commit 2eb3181

Browse files
fixed unfound node error when Suspense is filtered (facebook#20019)
* fixed unfound node error when Suspense is filtered * added a test for filtered Suspense node
1 parent c57fe4a commit 2eb3181

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

packages/react-devtools-shared/src/__tests__/__snapshots__/storeComponentFilters-test.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ exports[`Store component filters should not break when Suspense nodes are filter
9797
<Component>
9898
`;
9999
100+
exports[`Store component filters should not break when Suspense nodes are filtered from the tree: 3: suspended 1`] = `
101+
[root]
102+
▾ <Wrapper>
103+
▾ <Loading>
104+
<div>
105+
`;
106+
100107
exports[`Store component filters should support filtering by element type: 1: mount 1`] = `
101108
[root]
102109
▾ <Root>

packages/react-devtools-shared/src/__tests__/storeComponentFilters-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,8 @@ describe('Store component filters', () => {
256256

257257
act(() => ReactDOM.render(<Wrapper shouldSuspend={false} />, container));
258258
expect(store).toMatchSnapshot('2: resolved');
259+
260+
act(() => ReactDOM.render(<Wrapper shouldSuspend={true} />, container));
261+
expect(store).toMatchSnapshot('3: suspended');
259262
});
260263
});

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,9 @@ export function attach(
14371437
}
14381438

14391439
function recordResetChildren(fiber: Fiber, childSet: Fiber) {
1440+
if (__DEBUG__) {
1441+
debug('recordResetChildren()', childSet, fiber);
1442+
}
14401443
// The frontend only really cares about the displayName, key, and children.
14411444
// The first two don't really change, so we are only concerned with the order of children here.
14421445
// This is trickier than a simple comparison though, since certain types of fibers are filtered.
@@ -1471,6 +1474,23 @@ export function attach(
14711474
nextChildren.push(getFiberID(getPrimaryFiber(fiber)));
14721475
} else {
14731476
let child = fiber.child;
1477+
const isTimedOutSuspense =
1478+
fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
1479+
if (isTimedOutSuspense) {
1480+
// Special case: if Suspense mounts in a timed-out state,
1481+
// get the fallback child from the inner fragment,
1482+
// and skip over the primary child.
1483+
const primaryChildFragment = fiber.child;
1484+
const fallbackChildFragment = primaryChildFragment
1485+
? primaryChildFragment.sibling
1486+
: null;
1487+
const fallbackChild = fallbackChildFragment
1488+
? fallbackChildFragment.child
1489+
: null;
1490+
if (fallbackChild !== null) {
1491+
child = fallbackChild;
1492+
}
1493+
}
14741494
while (child !== null) {
14751495
findReorderedChildrenRecursively(child, nextChildren);
14761496
child = child.sibling;
@@ -1592,7 +1612,7 @@ export function attach(
15921612
if (nextFallbackChildSet != null) {
15931613
mountFiberRecursively(
15941614
nextFallbackChildSet,
1595-
nextFiber,
1615+
shouldIncludeInTree ? nextFiber : parentFiber,
15961616
true,
15971617
traceNearestHostComponentUpdate,
15981618
);

0 commit comments

Comments
 (0)