Skip to content

Commit 27a76c9

Browse files
committed
fix: sweep rebuilt tail on Hydrate resume for inherited calls
When a component's sole child inherits its range (M3 borrow) and that child rebuilds a root whose descendant suspends during a <Hydrate> activation, the server tail after the rebuilt root was never removed. The first activation's renderClaimed recorded the suspendedClaim for the wrapper block, but on resume findSuspendedHydrateBlock returned null (the scope walk couldn't reach the suspended block), so renderSuspended was never called and the claim was never consumed. The subsequent re-render path in componentSlotImpl just called renderBlock without claim management, leaving the rebuilt tail in the DOM. Fix: in the componentSlotImpl re-render path, check for a suspendedClaim on the block before falling through to renderBlock. When found, re-render the block and then explicitly sweep the rebuilt tail that the first activation's mismatch left behind.
1 parent 7ad462b commit 27a76c9

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19378,6 +19378,20 @@ class HydrationCapability {
1937819378
return this.unframedClaims?.get(block);
1937919379
}
1938019380

19381+
/** Consume a suspended adopted-range claim for `block` and sweep its rebuilt tail after re-render. */
19382+
resumeSuspendedClaim(block: Block): boolean {
19383+
const claim = this.suspendedClaims?.get(block);
19384+
if (claim === undefined) return false;
19385+
this.suspendedClaims!.delete(block);
19386+
const tail = this.rebuiltTail;
19387+
renderBlock(block);
19388+
if (tail !== null && this.rebuiltTail === tail) {
19389+
this.node = tail;
19390+
this.sweepRebuiltTail(block.endMarker!);
19391+
}
19392+
return true;
19393+
}
19394+
1938119395
/**
1938219396
* Resume `source`, the block that a preserved activation suspended in. Inside
1938319397
* a component whose unframed render suspended, it renders without adopting,
@@ -32994,8 +33008,13 @@ function componentSlotImpl(
3299433008
if (state.block.props !== renderProps)
3299533009
journalRootProperty(state.block, 'props', state.block.props);
3299633010
state.block.props = renderProps;
32997-
if (claim === undefined) renderBlock(state.block);
32998-
else hydration!.renderUnframed(renderBlock, state.block, state.block, claim);
33011+
if (claim === undefined) {
33012+
if (hydration !== null && hydration.resumeSuspendedClaim(state.block)) {
33013+
// The block re-rendered and its rebuilt tail was swept.
33014+
} else {
33015+
renderBlock(state.block);
33016+
}
33017+
} else hydration!.renderUnframed(renderBlock, state.block, state.block, claim);
3299933018
}
3300033019
// Hydration: advance the cursor PAST this component's adopted range so the next
3300133020
// sibling adopts from the right node. The body itself doesn't reliably leave the

‎packages/octane/tests/hydration/_fixtures/rebuilt-fragment-suspended-child.tsrx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ export function RebuiltRootBranch(props: { server?: boolean; leaf: Promise<strin
178178
</div>
179179
}
180180

181+
function ParaCall(props: { leaf: Promise<string> }) @{
182+
<Para leaf={props.leaf} />
183+
}
184+
185+
export function RebuiltRootInheritedBranch(props: { server?: boolean; leaf: Promise<string> }) @{
186+
<div>
187+
<Hydrate split={false} when={load()}>
188+
<section>
189+
@if (props.server) {
190+
<>
191+
<BoldThenEm />
192+
<Em />
193+
</>
194+
} @else {
195+
<>
196+
<ParaCall leaf={props.leaf} />
197+
<Em />
198+
</>
199+
}
200+
</section>
201+
</Hydrate>
202+
</div>
203+
}
204+
181205
function BoldThenItalic() @{
182206
<>
183207
<b class="server">{'server'}</b>

‎packages/octane/tests/hydration/rebuilt-fragment-suspended-child.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ describe.each([
217217
expect(warnings()).toHaveLength(dev ? 1 : 0);
218218
});
219219

220+
it('completes a child of a rebuilt root inside an inherited call, as when its data is ready', async () => {
221+
const name = 'RebuiltRootInheritedBranch';
222+
render(name, { server: true, leaf: fulfilled('unused') });
223+
await hydrate(name, { leaf: fulfilled('z') });
224+
const ready = markup(section());
225+
root!.unmount();
226+
recoverable = [];
227+
errSpy.mockClear();
228+
229+
render(name, { server: true, leaf: fulfilled('unused') });
230+
const leaf = pending();
231+
await hydrate(name, { leaf: leaf.promise });
232+
await act(async () => leaf.resolve('z'));
233+
234+
expect(markup(section().querySelector('p')!)).toBe('<em>z</em><s>s</s>');
235+
expect(markup(section())).toBe(ready);
236+
expect(recoverable).toEqual([expect.stringMatching(MISMATCH)]);
237+
expect(warnings()).toHaveLength(dev ? 1 : 0);
238+
});
239+
220240
it('keeps the root a fragment adopted after a hole whose call rebuilt its root, as when its data is ready', async () => {
221241
const name = 'RebuiltHoleBranch';
222242
render(name, { server: true, leaf: fulfilled('unused') });

0 commit comments

Comments
 (0)