Skip to content

Commit c486bc8

Browse files
committed
[DevTools] Fix handling of host roots on mount
1 parent 1f99bf2 commit c486bc8

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ describe('Store', () => {
492492
<Component key="Outside">
493493
▾ <Suspense>
494494
<Loading>
495-
[suspense-root] rects={null}
495+
[suspense-root] rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:10,height:1}]}
496496
<Suspense name="Wrapper>?" rects={null}>
497497
`);
498498

@@ -948,7 +948,7 @@ describe('Store', () => {
948948
▾ <Suspense name="three">
949949
<Component key="Suspense 3 Content">
950950
<Component key="Unrelated at End">
951-
[suspense-root] rects={null}
951+
[suspense-root] rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}]}
952952
<Suspense name="parent" rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}, {x:1,y:2,width:5,height:1}]}>
953953
<Suspense name="one" rects={[{x:1,y:2,width:5,height:1}]}>
954954
<Suspense name="two" rects={[{x:1,y:2,width:5,height:1}]}>
@@ -1053,7 +1053,7 @@ describe('Store', () => {
10531053
<Component key="A">
10541054
▾ <Suspense>
10551055
<Loading>
1056-
[suspense-root] rects={null}
1056+
[suspense-root] rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:10,height:1}]}
10571057
<Suspense name="Wrapper>?" rects={null}>
10581058
`);
10591059

@@ -1406,7 +1406,7 @@ describe('Store', () => {
14061406
expect(store).toMatchInlineSnapshot(`
14071407
[root]
14081408
▸ <Wrapper>
1409-
[suspense-root] rects={null}
1409+
[suspense-root] rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:10,height:1}]}
14101410
<Suspense name="Wrapper>?" rects={null}>
14111411
`);
14121412

@@ -1423,7 +1423,7 @@ describe('Store', () => {
14231423
<Component key="Outside">
14241424
▾ <Suspense>
14251425
<Loading>
1426-
[suspense-root] rects={null}
1426+
[suspense-root] rects={[{x:1,y:2,width:5,height:1}, {x:1,y:2,width:10,height:1}]}
14271427
<Suspense name="Wrapper>?" rects={null}>
14281428
`);
14291429

@@ -3081,8 +3081,8 @@ describe('Store', () => {
30813081
`);
30823082
});
30833083

3084-
it.failing('should handle an empty root', async () => {
3084+
it('should handle an empty root', async () => {
30853085
await actAsync(() => render(null));
3086-
expect(store).toMatchInlineSnapshot();
3086+
expect(store).toMatchInlineSnapshot(`[root]`);
30873087
});
30883088
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('Store component filters', () => {
156156
<div>
157157
▾ <Suspense>
158158
<div>
159-
[suspense-root] rects={null}
159+
[suspense-root] rects={[]}
160160
<Suspense name="Unknown" rects={[]}>
161161
<Suspense name="Unknown" rects={[]}>
162162
`);
@@ -174,7 +174,7 @@ describe('Store component filters', () => {
174174
<div>
175175
▾ <Suspense>
176176
<div>
177-
[suspense-root] rects={null}
177+
[suspense-root] rects={[]}
178178
<Suspense name="Unknown" rects={[]}>
179179
<Suspense name="Unknown" rects={[]}>
180180
`);
@@ -192,7 +192,7 @@ describe('Store component filters', () => {
192192
<div>
193193
▾ <Suspense>
194194
<div>
195-
[suspense-root] rects={null}
195+
[suspense-root] rects={[]}
196196
<Suspense name="Unknown" rects={[]}>
197197
<Suspense name="Unknown" rects={[]}>
198198
`);

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,28 +3700,32 @@ export function attach(
37003700
// just use the Fiber anyway.
37013701
// Fallbacks get attributed to the parent so we only measure if we're
37023702
// showing primary content.
3703-
if (OffscreenComponent === -1) {
3704-
const isTimedOut = fiber.memoizedState !== null;
3705-
if (!isTimedOut) {
3706-
newSuspenseNode.rects = measureInstance(newInstance);
3707-
}
3708-
} else {
3709-
const hydrated = isFiberHydrated(fiber);
3710-
if (hydrated) {
3711-
const contentFiber = fiber.child;
3712-
if (contentFiber === null) {
3713-
throw new Error(
3714-
'There should always be an Offscreen Fiber child in a hydrated Suspense boundary.',
3715-
);
3703+
if (fiber.tag === SuspenseComponent) {
3704+
if (OffscreenComponent === -1) {
3705+
const isTimedOut = fiber.memoizedState !== null;
3706+
if (!isTimedOut) {
3707+
newSuspenseNode.rects = measureInstance(newInstance);
37163708
}
37173709
} else {
3718-
// This Suspense Fiber is still dehydrated. It won't have any children
3719-
// until hydration.
3720-
}
3721-
const isTimedOut = fiber.memoizedState !== null;
3722-
if (!isTimedOut) {
3723-
newSuspenseNode.rects = measureInstance(newInstance);
3710+
const hydrated = isFiberHydrated(fiber);
3711+
if (hydrated) {
3712+
const contentFiber = fiber.child;
3713+
if (contentFiber === null) {
3714+
throw new Error(
3715+
'There should always be an Offscreen Fiber child in a hydrated Suspense boundary.',
3716+
);
3717+
}
3718+
} else {
3719+
// This Suspense Fiber is still dehydrated. It won't have any children
3720+
// until hydration.
3721+
}
3722+
const isTimedOut = fiber.memoizedState !== null;
3723+
if (!isTimedOut) {
3724+
newSuspenseNode.rects = measureInstance(newInstance);
3725+
}
37243726
}
3727+
} else {
3728+
newSuspenseNode.rects = measureInstance(newInstance);
37253729
}
37263730
recordSuspenseMount(newSuspenseNode, reconcilingParentSuspenseNode);
37273731
}

0 commit comments

Comments
 (0)