Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed unfound node error when Suspense is filtered #20019

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ exports[`Store component filters should not break when Suspense nodes are filter
<Component>
`;

exports[`Store component filters should not break when Suspense nodes are filtered from the tree: 3: suspended 1`] = `
[root]
▾ <Wrapper>
▾ <Loading>
<div>
`;

exports[`Store component filters should support filtering by element type: 1: mount 1`] = `
[root]
▾ <Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,8 @@ describe('Store component filters', () => {

act(() => ReactDOM.render(<Wrapper shouldSuspend={false} />, container));
expect(store).toMatchSnapshot('2: resolved');

act(() => ReactDOM.render(<Wrapper shouldSuspend={true} />, container));
expect(store).toMatchSnapshot('3: suspended');
});
});
22 changes: 21 additions & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@ export function attach(
}

function recordResetChildren(fiber: Fiber, childSet: Fiber) {
if (__DEBUG__) {
debug('recordResetChildren()', childSet, fiber);
}
// The frontend only really cares about the displayName, key, and children.
// The first two don't really change, so we are only concerned with the order of children here.
// This is trickier than a simple comparison though, since certain types of fibers are filtered.
Expand Down Expand Up @@ -1471,6 +1474,23 @@ export function attach(
nextChildren.push(getFiberID(getPrimaryFiber(fiber)));
} else {
let child = fiber.child;
const isTimedOutSuspense =
fiber.tag === SuspenseComponent && fiber.memoizedState !== null;
if (isTimedOutSuspense) {
// Special case: if Suspense mounts in a timed-out state,
// get the fallback child from the inner fragment,
// and skip over the primary child.
const primaryChildFragment = fiber.child;
const fallbackChildFragment = primaryChildFragment
? primaryChildFragment.sibling
: null;
const fallbackChild = fallbackChildFragment
? fallbackChildFragment.child
: null;
if (fallbackChild !== null) {
child = fallbackChild;
}
}
while (child !== null) {
findReorderedChildrenRecursively(child, nextChildren);
child = child.sibling;
Expand Down Expand Up @@ -1592,7 +1612,7 @@ export function attach(
if (nextFallbackChildSet != null) {
mountFiberRecursively(
nextFallbackChildSet,
nextFiber,
shouldIncludeInTree ? nextFiber : parentFiber,
true,
traceNearestHostComponentUpdate,
);
Expand Down