|
10 | 10 | * |
11 | 11 | * Per case, the shell is hydrated and every chunk applied, then: |
12 | 12 | * |
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. |
15 | 17 | * - CLEAN: no console.error, no hydration warning. |
16 | 18 | * - HYDRATED = CSR: the hydrated screen equals a fresh client render of the |
17 | 19 | * same inputs with every memo synchronous. |
|
24 | 26 | import { readFileSync, existsSync, writeFileSync } from "node:fs"; |
25 | 27 | import { resolve } from "node:path"; |
26 | 28 | 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"; |
28 | 31 | import { hydrate, render } from "@solidjs/web"; |
29 | 32 | import { sharedConfig } from "solid-js/internal"; |
30 | 33 | 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"; |
32 | 35 | import { describeScenario } from "../../async-gen/scenario.js"; |
33 | 36 | import { recordOrDiff, type Trace } from "../../async-gen/differential.js"; |
34 | 37 | import { serialize as serializeDom } from "../../async-gen/run.js"; |
@@ -87,26 +90,6 @@ async function freshScreen(createApp: (ctx: AppContext) => any, values: number[] |
87 | 90 | } |
88 | 91 | } |
89 | 92 |
|
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 | | - |
110 | 93 | async function runCase( |
111 | 94 | i: number |
112 | 95 | ): Promise<{ sc: Scenario; findings: Finding[]; screens: string[]; final: string }> { |
@@ -170,8 +153,14 @@ async function runCase( |
170 | 153 | guard("throw", flush); |
171 | 154 | }; |
172 | 155 |
|
| 156 | + // Each memo's hydration id, taken just before it is created. |
| 157 | + const ids = new Map<string, string>(); |
173 | 158 | const ctx: AppContext = { |
174 | 159 | values, |
| 160 | + id(name) { |
| 161 | + const owner = getOwner(); |
| 162 | + if (owner && !ids.has(name)) ids.set(name, String(peekNextChildId(owner))); |
| 163 | + }, |
175 | 164 | ask(name, v, poison) { |
176 | 165 | // Hydration's dry run swaps the global Promise for a mock: that run's |
177 | 166 | // flight is never consumed, so it is not an ask. |
@@ -206,10 +195,11 @@ async function runCase( |
206 | 195 | } |
207 | 196 | await drain(); |
208 | 197 | 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(":")))); |
213 | 203 | if (refetched.length) findings.push({ law: "refetch", step, detail: refetched.join(",") }); |
214 | 204 | const hydrated = serialize(container); |
215 | 205 | screens.push(hydrated); |
|
0 commit comments