Skip to content

Commit eb4e019

Browse files
ryansolidclaude
andauthored
fix(solid): a fragment revealed before its _fr settles hydrates the revealed content (#4074) (#4075)
* fix(solid): a fragment revealed before its _fr settles hydrates the revealed content (#4074) The still-streaming branch of hydratedCreateLoadingBoundary returned the fallback even when $df had already swapped the content in, so an async entry running between the reveal and the _fr settlement hydrated a removed fallback (Hydration key miss, detached element). Return nothing when the fragment is revealed; the existing resume adopts the content once _fr settles. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018fTNh1FgQx2WTF5xoxwML1 * size: re-record the two hydrating caps for #4074 Size-Exception: +30 B minified for the revealed-fragment check (#4074). Caps set at CI's measurement + 10 B. Accepted by the maintainer 2026-10-15. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018fTNh1FgQx2WTF5xoxwML1 --------- Co-authored-by: Claude <[email protected]>
1 parent 8cf8d65 commit eb4e019

4 files changed

Lines changed: 97 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
Hydration no longer hydrates a streamed `<Loading>` fallback when the fragment was already revealed but its `_fr` record hasn't settled yet (an async entry running between the two scripts). The boundary renders nothing and adopts the revealed content once the record settles (#4074).

‎packages/solid/src/client/hydration.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,11 @@ function hydratedCreateLoadingBoundary<T, U>(
28942894
false,
28952895
fragmentAbort(id)
28962896
);
2897-
return fallback();
2897+
// Revealed ahead of its `_fr` settlement (two scripts on the wire; an
2898+
// async entry can run between them, #4074): the fallback is gone and
2899+
// the content is in the DOM, so render nothing until the resume
2900+
// adopts it.
2901+
return (globalThis as any)._$HY.v?.[id] ? undefined : fallback();
28982902
}
28992903

29002904
if (assetPromise && !sharedConfig.has!(id)) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4074: the server writes a streamed fragment's reveal (`$df`) and the
6+
* script that settles its `<id>_fr` record as two scripts. An async entry
7+
* can start hydrating between them: the fragment is already swapped in
8+
* (`_$HY.v[id]`) while `_fr` still reads pending. The boundary must not
9+
* hydrate its fallback, which the reveal already removed (a "Hydration key
10+
* miss" and a detached element); it adopts the revealed content once `_fr`
11+
* settles.
12+
*
13+
* Replays the real server-rendered chunks of the late-boundary-after-done
14+
* harness scenario, split between the reveal and the settlement.
15+
*/
16+
import { expect, test, vi } from "vitest";
17+
import { readFileSync } from "node:fs";
18+
import { resolve, dirname } from "node:path";
19+
import { fileURLToPath } from "node:url";
20+
import { flush } from "solid-js";
21+
import { hydrate } from "@solidjs/web";
22+
import { scenarios } from "../harness/scenarios.jsx";
23+
24+
const artifactsDir = resolve(dirname(fileURLToPath(import.meta.url)), "../harness/__artifacts__");
25+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
26+
const scenario = scenarios.find(s => s.name === "late-boundary-after-done")!;
27+
28+
function applyChunk(container: HTMLDivElement, chunk: string, first: boolean) {
29+
const scriptRe = /<script(?:[^>]*)>([\s\S]*?)<\/script>/g;
30+
const scripts = [...chunk.matchAll(scriptRe)].map(m => m[1]);
31+
const stripped = chunk.replace(scriptRe, "");
32+
if (first) container.innerHTML = stripped;
33+
else container.insertAdjacentHTML("beforeend", stripped);
34+
return scripts;
35+
}
36+
37+
test("#4074: a fragment revealed before its _fr settles hydrates the revealed content", async () => {
38+
const { shell, rest } = JSON.parse(
39+
readFileSync(resolve(artifactsDir, `${scenario.name}.json`), "utf-8")
40+
);
41+
const container = document.createElement("div");
42+
document.body.appendChild(container);
43+
(globalThis as any)._$HY = { events: [], completed: new WeakSet(), r: {}, fe() {} };
44+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
45+
46+
for (const s of applyChunk(container, shell, true)) (0, eval)(s);
47+
const scripts = applyChunk(container, rest, false);
48+
// The reveal lands; the `_fr` settlement (the last script) has not.
49+
for (const s of scripts.slice(0, -1)) (0, eval)(s);
50+
expect(container.querySelector("p")).toBeNull();
51+
52+
const dispose = hydrate(() => <scenario.App />, container);
53+
flush();
54+
await sleep(10);
55+
(0, eval)(scripts[scripts.length - 1]);
56+
await sleep(50);
57+
flush();
58+
await sleep(10);
59+
flush();
60+
61+
expect(container.textContent).toBe(scenario.expectedText);
62+
// Claimed in place: the server node, not a client re-render.
63+
expect(container.querySelector("section")!.hasAttribute("_hk")).toBe(true);
64+
const misses = warn.mock.calls.filter(
65+
(c: unknown[]) => typeof c[0] === "string" && c[0].includes("Hydration key miss")
66+
);
67+
expect(misses).toEqual([]);
68+
warn.mockRestore();
69+
dispose();
70+
container.remove();
71+
});

‎scripts/size/scenarios.js‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,8 +2433,14 @@ module.exports = [
24332433
// whose own flush joins that hold back into it. Cap set at measured +
24342434
// 10 B rounded up to 0.01 KB. Accepted by the maintainer 2026-10-14
24352435
// (the floors unchanged, 0 B minified).
2436-
limit: "29.65 KB",
2437-
capMinified: 93714,
2436+
// Size-Exception (a fragment revealed before its _fr settles hydrates the
2437+
// revealed content, #4074, #4075, 2026-10-15): 29.65 -> 29.69 KB, CI measured
2438+
// 29,678 B (+30 B minified, 93,714 -> 93,753) — the still-streaming
2439+
// branch of hydratedCreateLoadingBoundary skips the fallback when `$df`
2440+
// already swapped the content in. Cap set at measured + 10 B rounded up
2441+
// to 0.01 KB. Accepted by the maintainer 2026-10-15.
2442+
limit: "29.69 KB",
2443+
capMinified: 93753,
24382444
alias
24392445
},
24402446
{
@@ -3772,8 +3778,14 @@ module.exports = [
37723778
// whose own flush joins that hold back into it. Cap set at measured +
37733779
// 10 B rounded up to 0.01 KB. Accepted by the maintainer 2026-10-14
37743780
// (the floors unchanged, 0 B minified).
3775-
limit: "31.78 KB",
3776-
capMinified: 101338,
3781+
// Size-Exception (a fragment revealed before its _fr settles hydrates the
3782+
// revealed content, #4074, #4075, 2026-10-15): 31.78 -> 31.89 KB, CI measured
3783+
// 31,871 B (+30 B minified, 101,338 -> 101,369) — the still-streaming
3784+
// branch of hydratedCreateLoadingBoundary skips the fallback when `$df`
3785+
// already swapped the content in. Cap set at measured + 10 B rounded up
3786+
// to 0.01 KB. Accepted by the maintainer 2026-10-15.
3787+
limit: "31.89 KB",
3788+
capMinified: 101369,
37773789
alias
37783790
},
37793791
{

0 commit comments

Comments
 (0)