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
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,78 @@ describe('Store component filters', () => {
`);
});

// @reactVersion >= 19.0
it('stays in sync when a filtered boundary suspends during a sibling restructure', async () => {
const neverResolves = new Promise(() => {});

function Reader() {
React.use(neverResolves);
return <div>read</div>;
}

function A({collapsed}) {
if (collapsed) {
return (
<React.Suspense fallback={<div>a-fb</div>}>
<Reader />
</React.Suspense>
);
}
return (
<React.Suspense fallback={<div>a-outer-fb</div>}>
<React.Suspense fallback={<div>a-inner-fb</div>}>
<Reader />
</React.Suspense>
<React.Suspense fallback={<div>a-sib-fb</div>}>
<div>a-sibling</div>
</React.Suspense>
</React.Suspense>
);
}

function App({collapsed, extra}) {
return (
<div>
{extra ? <em key="s">side</em> : null}
<A key="a" collapsed={collapsed} />
</div>
);
}

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

await actAsync(() => render(<App collapsed={false} extra={false} />));
expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <div>
▾ <A key="a">
<div>
<div>
`);

await actAsync(() => render(<App collapsed={true} extra={true} />));
expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <div>
<em key="s">
▾ <A key="a">
<div>
`);

await actAsync(() => render(<App collapsed={true} extra={false} />));
expect(store).toMatchInlineSnapshot(`
[root]
▾ <App>
▾ <div>
▾ <A key="a">
<div>
`);
});

describe('inline errors and warnings', () => {
const {render: legacyRender} = getLegacyRenderImplementation();

Expand Down
13 changes: 12 additions & 1 deletion packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3933,6 +3933,7 @@ export function attach(
nextFirstChild,
nextLastChild,
prevFirstChild,
null,
traceNearestHostComponentUpdate,
virtualLevel + 1,
);
Expand Down Expand Up @@ -3971,6 +3972,7 @@ export function attach(
nextFirstChild: Fiber,
nextLastChild: null | Fiber, // non-inclusive
prevFirstChild: null | Fiber,
prevLastChild: null | Fiber, // non-inclusive
traceNearestHostComponentUpdate: boolean,
virtualLevel: number, // the nth level of virtual instances
): UpdateFlags {
Expand Down Expand Up @@ -4247,7 +4249,10 @@ export function attach(
}
}
// If we have no more children, but used to, they don't line up.
if (prevChildAtSameIndex !== null) {
if (
prevChildAtSameIndex !== null &&
prevChildAtSameIndex !== prevLastChild
) {
updateFlags |= ShouldResetChildren | ShouldResetSuspenseChildren;
}
return updateFlags;
Expand All @@ -4266,6 +4271,7 @@ export function attach(
nextFirstChild,
null,
prevFirstChild,
null,
traceNearestHostComponentUpdate,
0,
);
Expand All @@ -4284,10 +4290,14 @@ export function attach(
const nextFallbackFiber = nextContentFiber.sibling;

// First update only the Offscreen boundary. I.e. the main content.
// The previous set is bounded by the previous fallback fragment since the
// fallback is reconciled separately below. Without the bound, a boundary
// that stays suspended would always report its content set as changed.
updateFlags |= updateVirtualChildrenRecursively(
nextContentFiber,
nextFallbackFiber,
prevContentFiber,
prevFallbackFiber,
traceNearestHostComponentUpdate,
0,
);
Expand All @@ -4306,6 +4316,7 @@ export function attach(
nextFallbackFiber,
null,
prevFallbackFiber,
null,
traceNearestHostComponentUpdate,
0,
);
Expand Down
Loading