Skip to content
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
96 changes: 96 additions & 0 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3298,4 +3298,100 @@ describe('Store', () => {
<Suspense name="Inner" rects={[{x:1,y:2,width:6,height:1}]}>
`);
});

// @reactVersion >= 19.0
it('measures rects when reconnecting', async () => {
function Component({children, promise}) {
let content = '';
if (promise) {
const value = readValue(promise);
if (typeof value === 'string') {
content += value;
}
}
return (
<div>
{content}
{children}
</div>
);
}

function App({outer, inner}) {
return (
<React.Suspense
name="outer"
fallback={<Component key="outer-fallback">loading outer</Component>}>
<Component key="outer-content" promise={outer}>
outer content
</Component>
<React.Suspense
name="inner"
fallback={
<Component key="inner-fallback">loading inner</Component>
}>
<Component key="inner-content" promise={inner}>
inner content
</Component>
</React.Suspense>
</React.Suspense>
);
}

await actAsync(() => {
render(<App outer={null} inner={null} />);
});

expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <Suspense name="outer">
<Component key="outer-content">
▾ <Suspense name="inner">
<Component key="inner-content">
[suspense-root] rects={[{x:1,y:2,width:13,height:1}, {x:1,y:2,width:13,height:1}]}
<Suspense name="outer" rects={[{x:1,y:2,width:13,height:1}, {x:1,y:2,width:13,height:1}]}>
<Suspense name="inner" rects={[{x:1,y:2,width:13,height:1}]}>
`);

let outerResolve;
const outerPromise = new Promise(resolve => {
outerResolve = resolve;
});

let innerResolve;
const innerPromise = new Promise(resolve => {
innerResolve = resolve;
});
await actAsync(() => {
render(<App outer={outerPromise} inner={innerPromise} />);
});

expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <Suspense name="outer">
<Component key="outer-fallback">
[suspense-root] rects={[{x:1,y:2,width:13,height:1}, {x:1,y:2,width:13,height:1}, {x:1,y:2,width:13,height:1}]}
<Suspense name="outer" rects={[{x:1,y:2,width:13,height:1}, {x:1,y:2,width:13,height:1}]}>
<Suspense name="inner" rects={[{x:1,y:2,width:13,height:1}]}>
`);

await actAsync(() => {
outerResolve('..');
innerResolve('.');
});

expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <Suspense name="outer">
<Component key="outer-content">
▾ <Suspense name="inner">
<Component key="inner-content">
[suspense-root] rects={[{x:1,y:2,width:15,height:1}, {x:1,y:2,width:14,height:1}]}
<Suspense name="outer" rects={[{x:1,y:2,width:15,height:1}, {x:1,y:2,width:14,height:1}]}>
<Suspense name="inner" rects={[{x:1,y:2,width:14,height:1}]}>
Copy link
Collaborator Author

@eps1lon eps1lon Nov 10, 2025

Choose a reason for hiding this comment

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

This measured a width of 13 without this change (see first commit) i.e. it was measuring without the resolved content.

`);
});
});
11 changes: 11 additions & 0 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,17 @@ export function attach(
}
}
} else {
const suspenseNode = fiberInstance.suspenseNode;
if (suspenseNode !== null && fiber.memoizedState === null) {
// We're reconnecting an unsuspended Suspense. Measure to see if anything changed.
const prevRects = suspenseNode.rects;
const nextRects = measureInstance(fiberInstance);
if (!areEqualRects(prevRects, nextRects)) {
suspenseNode.rects = nextRects;
recordSuspenseResize(suspenseNode);
}
}

const {key} = fiber;
const displayName = getDisplayNameForFiber(fiber);
const elementType = getElementTypeForFiber(fiber);
Expand Down
Loading