Skip to content

Commit e614e69

Browse files
IDrissAitHafidBrian Vaughn
andauthored
handled a missing suspense fiber when suspense is filtered on the profiler (facebook#19987)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
1 parent 7559722 commit e614e69

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ exports[`Store component filters should ignore invalid ElementTypeRoot filter: 2
8484
<div>
8585
`;
8686
87+
exports[`Store component filters should not break when Suspense nodes are filtered from the tree: 1: suspended 1`] = `
88+
[root]
89+
▾ <Wrapper>
90+
▾ <Loading>
91+
<div>
92+
`;
93+
94+
exports[`Store component filters should not break when Suspense nodes are filtered from the tree: 2: resolved 1`] = `
95+
[root]
96+
▾ <Wrapper>
97+
<Component>
98+
`;
99+
87100
exports[`Store component filters should support filtering by element type: 1: mount 1`] = `
88101
[root]
89102
▾ <Root>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,34 @@ describe('Store component filters', () => {
227227
]),
228228
);
229229
});
230+
231+
it('should not break when Suspense nodes are filtered from the tree', () => {
232+
const promise = new Promise(() => {});
233+
234+
const Loading = () => <div>Loading...</div>;
235+
236+
const Component = ({shouldSuspend}) => {
237+
if (shouldSuspend) {
238+
throw promise;
239+
}
240+
return null;
241+
};
242+
243+
const Wrapper = ({shouldSuspend}) => (
244+
<React.Suspense fallback={<Loading />}>
245+
<Component shouldSuspend={shouldSuspend} />
246+
</React.Suspense>
247+
);
248+
249+
store.componentFilters = [
250+
utils.createElementTypeFilter(Types.ElementTypeSuspense),
251+
];
252+
253+
const container = document.createElement('div');
254+
act(() => ReactDOM.render(<Wrapper shouldSuspend={true} />, container));
255+
expect(store).toMatchSnapshot('1: suspended');
256+
257+
act(() => ReactDOM.render(<Wrapper shouldSuspend={false} />, container));
258+
expect(store).toMatchSnapshot('2: resolved');
259+
});
230260
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ export function attach(
15721572
if (nextPrimaryChildSet !== null) {
15731573
mountFiberRecursively(
15741574
nextPrimaryChildSet,
1575-
nextFiber,
1575+
shouldIncludeInTree ? nextFiber : parentFiber,
15761576
true,
15771577
traceNearestHostComponentUpdate,
15781578
);

0 commit comments

Comments
 (0)