Skip to content

Commit 3873eec

Browse files
committed
test(web): async-gen refetch oracle counts only answers the payload carried
A first ask of a memo the server never streamed is not a refetch (#4313, #4414): the emitted app reports each memo's hydration id before creating it, and the hydration campaign counts an ask only when the shell or a chunk carries that id's answer. Re-run on next: the one remaining hydration finding (m2 after an errored root) goes away; 251 of 561 memos are served and still checked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWKJDzwaZPgaGWE181b
1 parent 4445560 commit 3873eec

2 files changed

Lines changed: 23 additions & 30 deletions

File tree

‎packages/web/test/async-gen/emit.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import type { Node, Read, Scenario, SrcRef } from "./scenario.js";
1414
export interface AppContext {
1515
values: number[];
1616
ask(name: string, v: number, poison: number | null): unknown;
17+
/** Called just before memo `name` is created (the client half reads the
18+
* hydration id it will take). */
19+
id?(name: string): void;
1720
}
1821

1922
const ref = (r: SrcRef) => (r.k === "s" ? `S[${r.i}][0]` : `M[${r.i}]`);
@@ -56,8 +59,8 @@ export function emitApp(sc: Scenario): string {
5659
.join(" + ");
5760
const poison = m.poison === null ? "null" : String(m.poison);
5861
return m.async
59-
? ` M[${i}] = createMemo(() => { const v = 1 + ${input}; return ctx.ask("m${i}", v, ${poison}); });`
60-
: ` M[${i}] = createMemo(() => { const v = 1 + ${input}; if (${poison} !== null && v % 4 === ${poison}) throw new Error("m${i}:" + v); return v; });`;
62+
? ` ctx.id?.("m${i}");\n M[${i}] = createMemo(() => { const v = 1 + ${input}; return ctx.ask("m${i}", v, ${poison}); });`
63+
: ` ctx.id?.("m${i}");\n M[${i}] = createMemo(() => { const v = 1 + ${input}; if (${poison} !== null && v % 4 === ${poison}) throw new Error("m${i}:" + v); return v; });`;
6164
})
6265
.join("\n");
6366
return `/**

‎packages/web/test/consistency/async-gen/hydrate.spec.tsx‎

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
*
1111
* Per case, the shell is hydrated and every chunk applied, then:
1212
*
13-
* - NO REFETCH: no memo asks again before the first client write (an ask
14-
* made under hydration's dry run, with its fake Promise, is not one).
13+
* - NO REFETCH: no memo whose answer (value or error) the server sent asks
14+
* again before the first client write. A first ask of something the
15+
* payload never carried is not a refetch (#4313, #4414), nor is an ask
16+
* made under hydration's dry run, with its fake Promise.
1517
* - CLEAN: no console.error, no hydration warning.
1618
* - HYDRATED = CSR: the hydrated screen equals a fresh client render of the
1719
* same inputs with every memo synchronous.
@@ -24,11 +26,12 @@
2426
import { readFileSync, existsSync, writeFileSync } from "node:fs";
2527
import { resolve } from "node:path";
2628
import { expect, test } from "vitest";
27-
import { action, flush, resetErrorHalt } from "solid-js";
29+
import { action, flush, getOwner, resetErrorHalt } from "solid-js";
30+
import { peekNextChildId } from "@solidjs/signals";
2831
import { hydrate, render } from "@solidjs/web";
2932
import { sharedConfig } from "solid-js/internal";
3033
import type { AppContext } from "../../async-gen/emit.js";
31-
import type { Node, Scenario, SrcRef } from "../../async-gen/scenario.js";
34+
import type { Scenario } from "../../async-gen/scenario.js";
3235
import { describeScenario } from "../../async-gen/scenario.js";
3336
import { recordOrDiff, type Trace } from "../../async-gen/differential.js";
3437
import { serialize as serializeDom } from "../../async-gen/run.js";
@@ -87,26 +90,6 @@ async function freshScreen(createApp: (ctx: AppContext) => any, values: number[]
8790
}
8891
}
8992

90-
/** The memos the tree reads, directly or through other memos. */
91-
function readMemos(sc: Scenario): Set<number> {
92-
const out = new Set<number>();
93-
const add = (r: SrcRef) => {
94-
if (r.k !== "m" || out.has(r.i)) return;
95-
out.add(r.i);
96-
sc.memos[r.i].deps.forEach(d => add(d.src));
97-
};
98-
const walk = (n: Node) => {
99-
if (n.t === "leaf") [...n.text, ...n.attrs].forEach(r => add(r.src));
100-
else if (n.t === "group") n.kids.forEach(walk);
101-
else {
102-
if (n.t === "show") add(n.when.src);
103-
walk(n.child);
104-
}
105-
};
106-
walk(sc.tree);
107-
return out;
108-
}
109-
11093
async function runCase(
11194
i: number
11295
): Promise<{ sc: Scenario; findings: Finding[]; screens: string[]; final: string }> {
@@ -170,8 +153,14 @@ async function runCase(
170153
guard("throw", flush);
171154
};
172155

156+
// Each memo's hydration id, taken just before it is created.
157+
const ids = new Map<string, string>();
173158
const ctx: AppContext = {
174159
values,
160+
id(name) {
161+
const owner = getOwner();
162+
if (owner && !ids.has(name)) ids.set(name, String(peekNextChildId(owner)));
163+
},
175164
ask(name, v, poison) {
176165
// Hydration's dry run swaps the global Promise for a mock: that run's
177166
// flight is never consumed, so it is not an ask.
@@ -206,10 +195,11 @@ async function runCase(
206195
}
207196
await drain();
208197
hydrating = false;
209-
// A memo the page never reads is never streamed (the server answers
210-
// what the render waited on), so its client ask is not a refetch.
211-
const read = readMemos(sc);
212-
const refetched = asks.filter(a => read.has(Number(a.slice(1, a.indexOf(":")))));
198+
// Only an answer the payload carried can be re-asked.
199+
const payload = shell + chunks.join("");
200+
const served = (name: string) =>
201+
ids.has(name) && payload.includes(`_$HY.r["${ids.get(name)}"]`);
202+
const refetched = asks.filter(a => served(a.slice(0, a.indexOf(":"))));
213203
if (refetched.length) findings.push({ law: "refetch", step, detail: refetched.join(",") });
214204
const hydrated = serialize(container);
215205
screens.push(hydrated);

0 commit comments

Comments
 (0)