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

handled a missing suspense fiber when suspense is filtered on the profiler #19987

Merged
merged 2 commits into from
Oct 13, 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 @@ -84,6 +84,19 @@ exports[`Store component filters should ignore invalid ElementTypeRoot filter: 2
<div>
`;

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

exports[`Store component filters should not break when Suspense nodes are filtered from the tree: 2: resolved 1`] = `
[root]
▾ <Wrapper>
<Component>
`;

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 @@ -227,4 +227,34 @@ describe('Store component filters', () => {
]),
);
});

it('should not break when Suspense nodes are filtered from the tree', () => {
const promise = new Promise(() => {});

const Loading = () => <div>Loading...</div>;

const Component = ({shouldSuspend}) => {
if (shouldSuspend) {
throw promise;
}
return null;
};

const Wrapper = ({shouldSuspend}) => (
<React.Suspense fallback={<Loading />}>
<Component shouldSuspend={shouldSuspend} />
</React.Suspense>
);

store.componentFilters = [
utils.createElementTypeFilter(Types.ElementTypeSuspense),
];

const container = document.createElement('div');
act(() => ReactDOM.render(<Wrapper shouldSuspend={true} />, container));
expect(store).toMatchSnapshot('1: suspended');

act(() => ReactDOM.render(<Wrapper shouldSuspend={false} />, container));
expect(store).toMatchSnapshot('2: resolved');
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ export function attach(
if (nextPrimaryChildSet !== null) {
mountFiberRecursively(
nextPrimaryChildSet,
nextFiber,
shouldIncludeInTree ? nextFiber : parentFiber,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Looks like we handled this correctly in 5 of the 6 places, but missed this one. Great find! 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

true,
traceNearestHostComponentUpdate,
);
Expand Down