Skip to content

Commit 77be406

Browse files
ryansolidclaude
andauthored
fix(signals): latest() and isPending() in a hydration claim read the server's snapshot (#4570) (#4581)
* fix(signals): latest() and isPending() in a hydration claim read the server's snapshot (#4570) A client write during the hydration window, while a streamed boundary is still out, re-arms a <Loading on> nested in it. When the server's answer streams in, the boundary resumes in a snapshot scope: a plain read is served the value the server rendered with, but latest() and isPending() read through the verdict window, which did not serve it. latest(a1) beside a1() saw the client's flight (a1:1, no value yet), threw, and put the inner boundary in a fallback the server never rendered, claimed against nothing: "Hydration key miss", a detached <p>F1</p>, and F1 beside the snapshot's a1=10 (F-1; D-16 says that re-arm's fallback never shows). verdictValue now serves the snapshot to a reader in a snapshot scope, as read() does, marking it stale so it replays at the scope's release. The code is in the verdict engine: apps without latest/isPending pay nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * perf(signals): one snapshot-serve helper for read() and the verdict window (#4570) The verdict window's copy of read()'s snapshot serve cost the live pages 125-159 B minified. Both sites now call one helper, servedSnapshot, behind the same inline guard, so builds that never hydrate still fold both away. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * Revert "perf(signals): one snapshot-serve helper for read() and the verdict window (#4570)" This reverts commit d1000a8. * perf(signals): re-run a claim's verdict reader at release without comparing (#4570) A verdict reader served the server's snapshot in a hydration claim is marked stale unconditionally; read() already compares before re-running. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * Revert "perf(signals): re-run a claim's verdict reader at release without comparing (#4570)" The unconditional re-run makes a verdict reader in a claim emit twice at release (create-deferred-hydration.spec.ts, D-40). Keep the compare. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE --------- Co-authored-by: Claude <[email protected]>
1 parent 8cac5f0 commit 77be406

8 files changed

Lines changed: 310 additions & 1 deletion
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
fix(signals): `latest()` and `isPending()` in a hydration claim read the server's snapshot, as a plain read does, so a client write during the hydration window no longer puts a nested `<Loading on>` into a fallback the server never rendered (a "Hydration key miss") (#4570)

‎packages/signals/src/core/verdict.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
CONFIG_ASYNC,
1616
CONFIG_HELD,
1717
CONFIG_HELD_FRAME,
18+
CONFIG_IN_SNAPSHOT_SCOPE,
1819
CONFIG_INPUTS_PUBLISHED,
1920
CONFIG_OVERRIDE,
2021
CONFIG_REDERIVE,
@@ -23,12 +24,14 @@ import {
2324
EFFECT_RENDER,
2425
EFFECT_TRACKED,
2526
NOT_PENDING,
27+
NO_SNAPSHOT,
2628
REACTIVE_DISPOSED,
2729
REACTIVE_FRAME_READ,
2830
REACTIVE_JOINED,
2931
REACTIVE_LANE_READ,
3032
REACTIVE_PROBED,
3133
REACTIVE_REASK,
34+
REACTIVE_SNAPSHOT_STALE,
3235
REACTIVE_PROBE_UNANSWERED,
3336
REACTIVE_STAGED_READ,
3437
REACTIVE_WINDOW,
@@ -46,6 +49,7 @@ import {
4649
prepareComputed,
4750
pullComputed,
4851
setVerdict,
52+
snapshotCaptureActive,
4953
spectating,
5054
strictRead,
5155
strictReadActive,
@@ -79,6 +83,7 @@ import {
7983
SLOT_DV,
8084
SLOT_LV,
8185
SLOT_P,
86+
SLOT_SNAPSHOT,
8287
shadowActual,
8388
shadowExpect,
8489
shadowWindow
@@ -448,8 +453,27 @@ function verdictValue(el: Signal<any> | Computed<any>, c: Computed<any> | null):
448453
setVerdict(verdictValue);
449454
latestActive = prevLatest;
450455
probing = prevProbing;
456+
// A reader in a snapshot scope (a hydration claim) is served the value the
457+
// server rendered with, as `read` serves a plain one: `latest(a)` beside
458+
// `a()` in a claim shows the server's frame whole (F-1), not a client
459+
// write's flight the markup never had — which would put a boundary over
460+
// it in a fallback the server never rendered, claimed against nothing
461+
// (#4570). `isPending` answers for that frame: nothing in flight. The
462+
// reader replays at the scope's release.
463+
const sv =
464+
snapshotCaptureActive && c && c._config & CONFIG_IN_SNAPSHOT_SCOPE
465+
? el._x?._snapshotValue
466+
: undefined,
467+
served = sv !== undefined && !(owner._statusFlags & STATUS_ERROR);
451468
// Shadow (S0): the window's decision point — the rows Vl*/Vp*.
452-
if (__TEST__) shadowExpect(c, el, tracking, latestActive ? 2 : 1, spectating, false);
469+
if (__TEST__) shadowExpect(c, el, tracking, latestActive ? 2 : 1, spectating, served);
470+
if (served) {
471+
const snapshot = sv === NO_SNAPSHOT ? undefined : sv;
472+
if ((el._pendingValue !== NOT_PENDING ? el._pendingValue : el._value) !== snapshot)
473+
c!._flags |= REACTIVE_SNAPSHOT_STALE;
474+
if (__TEST__) shadowActual(SLOT_SNAPSHOT);
475+
return snapshot;
476+
}
453477
// A live `affects()` mark on the node or a dependency (affects.ts): not
454478
// final by declaration — the value itself is read as below. The verdict is
455479
// display-ahead like any: in a transaction's flush (the declaring action's
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
clearSnapshots,
3+
createMemo,
4+
createRoot,
5+
createSignal,
6+
flush,
7+
getOwner,
8+
isPending,
9+
latest,
10+
markSnapshotScope,
11+
releaseSnapshotScope,
12+
runWithOwner,
13+
setSnapshotCapture
14+
} from "../src/index.js";
15+
16+
// #4570: a reader in a snapshot scope (a hydration claim) is served the value
17+
// the server rendered with. `latest()` and `isPending()` read through the
18+
// verdict window, which must serve the snapshot as a plain read does: in a
19+
// claim, `latest(a)` beside `a()` shows the server's frame whole (F-1).
20+
afterEach(() => {
21+
clearSnapshots();
22+
setSnapshotCapture(false);
23+
flush();
24+
});
25+
26+
describe("#4570: verdict reads in a snapshot scope", () => {
27+
it("latest() and a plain read agree on the snapshot until release", () => {
28+
let setX!: (v: number) => void;
29+
let $x!: () => number;
30+
let owner!: any;
31+
createRoot(() => {
32+
[$x, setX] = createSignal(1);
33+
setSnapshotCapture(true);
34+
owner = getOwner()!;
35+
markSnapshotScope(owner);
36+
});
37+
38+
// A client write before the claim's readers exist.
39+
setX(5);
40+
flush();
41+
42+
let plain!: () => number, viaLatest!: () => number, pending!: () => boolean;
43+
runWithOwner(owner, () => {
44+
plain = createMemo(() => $x());
45+
viaLatest = createMemo(() => latest($x));
46+
pending = createMemo(() => isPending($x));
47+
});
48+
expect([plain(), viaLatest(), pending()]).toEqual([1, 1, false]);
49+
50+
releaseSnapshotScope(owner);
51+
flush();
52+
expect([plain(), viaLatest(), pending()]).toEqual([5, 5, false]);
53+
});
54+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"shell": "<main _hk=2><template id=\"pl-300\"></template><p _hk=3000>F0</p><!--pl-300--></main><script>(self.$R=self.$R||{})[\"\"]=[];_$HY.r[\"0\"]=$R[0]=($R[1]=($R[2]=() => {\n\tconst resolver = {\n\t\tp: 0,\n\t\ts: 0,\n\t\tf: 0\n\t};\n\tresolver.p = new Promise((resolve, reject) => {\n\t\tresolver.s = resolve;\n\t\tresolver.f = reject;\n\t});\n\treturn resolver;\n})()).p;_$HY.r[\"1\"]=$R[3]=($R[4]=$R[2]()).p;_$HY.r[\"300000_fr\"]=$R[5]=($R[6]=$R[2]()).p;_$HY.r[\"300_fr\"]=$R[7]=($R[8]=$R[2]()).p;</script>",
3+
"chunks": [
4+
"<script>($R[9]=(resolver, data) => {\n\tresolver.s(data);\n\tresolver.p.s = 1;\n\tresolver.p.v = data;\n})($R[4],10);</script><script>$R[9]($R[6],!0);</script>",
5+
"<template id=\"300\"><i _hk=300000010>La2=<!--$-->10<!--/--></i><p _hk=300001>a1=<!--$-->10<!--/--></p></template><script>$R[9]($R[1],10);$df(\"300\");function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!==\"pl-\"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,(_$HY.v=_$HY.v||{})[e]=n.hasAttribute(\"e\")?[...n.content.childNodes]:1,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue===\"pl-\"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}function $dfe(e,t,k){(t=e.target)&&t.getAttribute&&!t._$dc&&(k=t.getAttribute(\"data-dfc\"))&&(t._$dc=1,$dfc(k))}document.addEventListener(\"load\",$dfe,!0);document.addEventListener(\"error\",$dfe,!0);</script><script>$R[9]($R[8],!0);</script>"
6+
]
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"shell": "<main _hk=1><template id=\"pl-200\"></template><p _hk=2000>F0</p><!--pl-200--></main><script>(self.$R=self.$R||{})[\"\"]=[];_$HY.r[\"0\"]=$R[0]=($R[1]=($R[2]=() => {\n\tconst resolver = {\n\t\tp: 0,\n\t\ts: 0,\n\t\tf: 0\n\t};\n\tresolver.p = new Promise((resolve, reject) => {\n\t\tresolver.s = resolve;\n\t\tresolver.f = reject;\n\t});\n\treturn resolver;\n})()).p;_$HY.r[\"200000_fr\"]=$R[3]=($R[4]=$R[2]()).p;_$HY.r[\"200_fr\"]=$R[5]=($R[6]=$R[2]()).p;</script>",
3+
"chunks": [
4+
"<template id=\"200\"><i _hk=200000010>La1=<!--$-->10<!--/--></i><p _hk=200001>a1=<!--$-->10<!--/--></p></template><script>($R[7]=(resolver, data) => {\n\tresolver.s(data);\n\tresolver.p.s = 1;\n\tresolver.p.v = data;\n})($R[1],10);$df(\"200\");function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!==\"pl-\"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,(_$HY.v=_$HY.v||{})[e]=n.hasAttribute(\"e\")?[...n.content.childNodes]:1,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue===\"pl-\"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}function $dfe(e,t,k){(t=e.target)&&t.getAttribute&&!t._$dc&&(k=t.getAttribute(\"data-dfc\"))&&(t._$dc=1,$dfc(k))}document.addEventListener(\"load\",$dfe,!0);document.addEventListener(\"error\",$dfe,!0);</script><script>$R[7]($R[4],!0);$R[7]($R[6],!0);</script>"
5+
]
6+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
*
4+
* #4570: a `<Loading on={s0()}>` nested in a streamed `<Loading>`. The
5+
* server streams the outer fallback and holds the stream open while `a1`
6+
* is out. The client hydrates in that window and writes `s0` before the
7+
* server's answer arrives.
8+
*
9+
* `shared` (the issue): the inner content reads `latest(a1)`, `a1` is keyed
10+
* by `s0` and also read in the outer boundary, outside the inner one.
11+
* `own`: `a1` is not keyed by `s0`; the inner content reads its own async
12+
* `a2` keyed by `s0`, which nothing outside the inner boundary reads.
13+
*
14+
* Compiled with both generates: test/server/hydration-write-rearm-4570.gen.spec.tsx
15+
* writes the chunks test/hydration/hydration-write-rearm-4570.spec.tsx replays.
16+
*/
17+
import { createMemo, createSignal, Errored, latest, Loading } from "solid-js";
18+
import { isServer } from "@solidjs/web";
19+
20+
const RealPromise = Promise;
21+
22+
export type WriteRearmShape = "shared" | "own";
23+
export const writeRearmShapes: WriteRearmShape[] = ["shared", "own"];
24+
export const writeRearmName = (o: WriteRearmShape) => `hydration-write-rearm-4570-${o}`;
25+
26+
export function createWriteRearmApp(o: WriteRearmShape) {
27+
const [s0, setS0] = createSignal(0);
28+
const asks: string[] = [];
29+
const flights = new Map<string, { p: Promise<number>; resolve: (v: number) => void }>();
30+
const ask = (key: string): Promise<number> => {
31+
// The server answers 10 to everything; `a2` before `a1`, so the outer
32+
// boundary's fragment carries the inner content, not its fallback.
33+
if (isServer) return new RealPromise(r => setTimeout(() => r(10), key[1] === "2" ? 10 : 20));
34+
if (Promise === RealPromise) asks.push(key);
35+
let f = flights.get(key);
36+
if (!f) {
37+
let resolve!: (v: number) => void;
38+
const p = new RealPromise<number>(r => (resolve = r));
39+
flights.set(key, (f = { p, resolve }));
40+
}
41+
return f.p;
42+
};
43+
function App() {
44+
const a1 = createMemo(() => ask(o === "shared" ? "a1:" + s0() : "a1"));
45+
const a2 = o === "own" ? createMemo(() => ask("a2:" + s0())) : undefined;
46+
return (
47+
<main>
48+
<Errored fallback={<p>error</p>}>
49+
<Loading fallback={<p>F0</p>}>
50+
<Loading on={s0()} fallback={<p>F1</p>}>
51+
{a2 ? <i>La2={a2()}</i> : <i>La1={latest(a1)}</i>}
52+
</Loading>
53+
<p>a1={a1()}</p>
54+
</Loading>
55+
</Errored>
56+
</main>
57+
);
58+
}
59+
return {
60+
App,
61+
write: (v: number) => setS0(v),
62+
land: (key: string, v: number) => flights.get(key)?.resolve(v),
63+
asks: () => asks
64+
};
65+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4570: a client write during the hydration window, while a streamed
6+
* boundary is still out, re-arms a `<Loading on>` nested in it. When the
7+
* server's answer streams in, the boundary resumes against the server
8+
* snapshot and catches up to the write. The re-arm's data (`a1`) is also
9+
* read outside the inner boundary, so its fallback is never shown (D-16):
10+
* the catch-up holds the whole content on the snapshot until `a1:1` lands
11+
* (F-2), and no frame shows the inner fallback beside the snapshot's answer
12+
* (F-1). The inner fallback is never claimed against the server's markup,
13+
* which never rendered it: no "Hydration key miss", no detached element.
14+
* Nothing the server answered is asked again. Replays the chunks
15+
* test/server/hydration-write-rearm-4570.gen.spec.tsx renders.
16+
*/
17+
import { afterEach, describe, expect, test, vi } from "vitest";
18+
import { readFileSync } from "node:fs";
19+
import { dirname, resolve } from "node:path";
20+
import { fileURLToPath } from "node:url";
21+
import { flush } from "solid-js";
22+
import { hydrate } from "@solidjs/web";
23+
import {
24+
createWriteRearmApp,
25+
writeRearmName,
26+
writeRearmShapes,
27+
type WriteRearmShape
28+
} from "../harness/hydration-write-rearm-4570.jsx";
29+
import { bootstrapHydrationGlobal } from "../harness/hydration-bootstrap.js";
30+
31+
const load = (name: string) =>
32+
JSON.parse(
33+
readFileSync(
34+
resolve(dirname(fileURLToPath(import.meta.url)), `../harness/__artifacts__/${name}.json`),
35+
"utf-8"
36+
)
37+
) as { shell: string; chunks: string[] };
38+
39+
// What the screen shows once the server's answer has streamed in (the write
40+
// already made), and once the client's own question lands.
41+
// - shared: `a1` is read outside the inner boundary, so the re-arm's
42+
// fallback is never shown (D-16); the catch-up holds the whole content on
43+
// the snapshot until `a1:1` lands (F-2, F-1).
44+
// - own: nothing outside waits on `a2:1`, so the re-arm's fallback shows
45+
// now (D-15), created fresh: the server never rendered it.
46+
const expected: Record<WriteRearmShape, { resumed: string; landed: string; asks: string[] }> = {
47+
shared: { resumed: "La1=10a1=10", landed: "La1=11a1=11", asks: ["a1:1"] },
48+
own: { resumed: "F1a1=10", landed: "La2=11a1=10", asks: ["a2:1"] }
49+
};
50+
const lands: Record<WriteRearmShape, string> = { shared: "a1:1", own: "a2:1" };
51+
52+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
53+
async function settle() {
54+
for (let i = 0; i < 4; i++) {
55+
await sleep(5);
56+
flush();
57+
}
58+
}
59+
60+
function applyChunk(container: HTMLElement, chunk: string, first: boolean) {
61+
const scriptRe = /<script(?:[^>]*)>([\s\S]*?)<\/script>/g;
62+
const scripts = [...chunk.matchAll(scriptRe)].map(m => m[1]);
63+
const stripped = chunk.replace(scriptRe, "");
64+
if (first) container.innerHTML = stripped;
65+
else container.insertAdjacentHTML("beforeend", stripped);
66+
for (const s of scripts) (0, eval)(s);
67+
}
68+
69+
afterEach(async () => {
70+
await sleep(0);
71+
delete (globalThis as any)._$HY;
72+
});
73+
74+
describe("#4570: a write in the hydration window re-arms a nested Loading", () => {
75+
for (const o of writeRearmShapes) {
76+
test(o, async () => {
77+
const artifact = load(writeRearmName(o));
78+
bootstrapHydrationGlobal();
79+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
80+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
81+
const container = document.createElement("div");
82+
document.body.appendChild(container);
83+
const { App, write, land, asks } = createWriteRearmApp(o);
84+
const text = () => container.querySelector("main")!.textContent;
85+
let dispose: (() => void) | undefined;
86+
try {
87+
applyChunk(container, artifact.shell, true);
88+
dispose = hydrate(() => <App />, container);
89+
await settle();
90+
expect(text()).toBe("F0");
91+
92+
// The write lands while the server's answer is still out.
93+
write(1);
94+
await settle();
95+
expect(text()).toBe("F0");
96+
97+
// The server's answer streams in: the boundary resumes on the
98+
// snapshot, then catches up to the write.
99+
for (const c of artifact.chunks) {
100+
applyChunk(container, c, false);
101+
await settle();
102+
}
103+
expect(text()).toBe(expected[o].resumed);
104+
// Every node on screen is in the document: nothing rendered detached.
105+
for (const p of container.querySelectorAll("main p, main i"))
106+
expect(p.isConnected).toBe(true);
107+
108+
land(lands[o], 11);
109+
await settle();
110+
expect(text()).toBe(expected[o].landed);
111+
// Nothing the server answered is asked again.
112+
expect(asks()).toEqual(expected[o].asks);
113+
114+
const diagnostics = [...warn.mock.calls, ...error.mock.calls].map(c => String(c[0]));
115+
expect(diagnostics).toEqual([]);
116+
} finally {
117+
dispose?.();
118+
container.remove();
119+
warn.mockRestore();
120+
error.mockRestore();
121+
}
122+
});
123+
}
124+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
*
4+
* Server half of test/hydration/hydration-write-rearm-4570.spec.tsx: renders
5+
* the app and writes its shell plus each later chunk.
6+
*/
7+
import { expect, test } from "vitest";
8+
import {
9+
createWriteRearmApp,
10+
writeRearmName,
11+
writeRearmShapes
12+
} from "../harness/hydration-write-rearm-4570.jsx";
13+
import { recordStream, writeArtifact } from "./artifact-recorder.js";
14+
15+
for (const o of writeRearmShapes) {
16+
const name = writeRearmName(o);
17+
test(`render ${name} chunks`, async () => {
18+
const { App } = createWriteRearmApp(o);
19+
const { shell, chunks } = await recordStream(() => <App />);
20+
expect(shell).toContain("F0");
21+
expect(chunks.join("")).toContain("a1=");
22+
writeArtifact(name, { shell, chunks });
23+
});
24+
}

0 commit comments

Comments
 (0)