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

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
This commit is contained in:
IDrissAitHafid
2020-10-13 18:38:58 +01:00
committed by GitHub
parent 7559722a86
commit e614e69657
3 changed files with 44 additions and 1 deletions

View File

@@ -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>

View File

@@ -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');
});
});

View File

@@ -1572,7 +1572,7 @@ export function attach(
if (nextPrimaryChildSet !== null) {
mountFiberRecursively(
nextPrimaryChildSet,
nextFiber,
shouldIncludeInTree ? nextFiber : parentFiber,
true,
traceNearestHostComponentUpdate,
);