You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 44f4b76
Browse filesBrowse the repository at this point in the historyBrowse files
fix(web): hydrate() waits for the shell records when a stylesheet delays them (#3610)
A still-loading <link rel="stylesheet"> blocks every parser-inserted
classic <script> after it, but not an `async` module entry, so hydrate()
could run against the bootstrap's empty `_$HY.r`: a streamed <Loading>
found neither its record nor its `_fr` declaration and fell through to
the core boundary — a `Hydration key miss` on the fallback, a real client
refetch, and a `$df` swap nobody claimed.
Readiness gate on `_$HY`:
- Server: `generateHydrationScript()` (hand-built documents, where the
host places the bootstrap apart from the records script the render
appends to its output) marks the bootstrap `p:1` — records may be
parser-pending. `<HydrationScript />` omits it: assembleDocument splices
the shell's records script immediately after it at `<!--xs-->`, so the
two execute back to back and nothing can be pending between them. A
hand-constructed `_$HY` keeps the same default: absent means ready.
- Client: with the flag set, the parser still running, and no record
landed, hydrate() parks its start on the first `_$HY.r` write (a Proxy
that hands the object back on that write; the start rides a microtask
so the whole records script is visible) or DOMContentLoaded — the
parser finishing is the proof that no records script is coming. The
dispose function is still returned synchronously and cancels a parked
start. Post-load hydrate() (module/deferred entries) never waits.
Size: +137 B / +129 B brotli on the two hydrating scenarios (web only, in
hydrate() itself); caps 20.95 -> 21.10 KB and 31.2 -> 31.30 KB with dated
ledger notes.
Fixes#3610
Co-authored-by: Claude <[email protected]>
fix(web): `hydrate()` waits for the document's records when a stylesheet delays them (#3610)
6
+
7
+
A still-loading stylesheet blocks the classic records `<script>` but not an `async` module entry, so `hydrate()` could start against the bootstrap's empty `_$HY.r`: a streamed `<Loading>` fell through to a fresh boundary (a `Hydration key miss` on its fallback, a client refetch, a `$df` swap nobody claimed). `generateHydrationScript()` — hand-built documents, where the bootstrap and the records are placed apart — now marks the bootstrap `p:1`; with that flag, mid-parse, and no record landed, `hydrate()` parks its start until the first `_$HY.r` write or `DOMContentLoaded`. `<HydrationScript />` omits the flag (its records are spliced right after it), so JSX documents and post-load hydration are unchanged. The dispose function is still returned synchronously and cancels a parked start.
Copy file name to clipboardExpand all lines: documentation/solid-2.0/12-ssr-http.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ Server (`@solidjs/web` under the `node`/`deno`/`worker` conditions):
28
28
29
29
For hydration, the document needs the hydration script ahead of the app markup: `generateHydrationScript({ nonce?, eventNames? })` returns it as a string for hand-built documents, and `<HydrationScript />` renders it in JSX documents.
30
30
31
+
The serialized hydration records (`_$HY.r`) are written by classic inline `<script>`s; a still-loading `<link rel="stylesheet">` blocks every parser-inserted classic script after it but not an `async` module entry, so `hydrate()` can run before the records have. `hydrate()` therefore has a readiness gate (#3610). In a JSX document the shell's records script is spliced immediately after `<HydrationScript />`, so the two can never be separated and hydration starts on the spot — with or without records, even mid-parse. A hand-built document places `generateHydrationScript()` itself, apart from the records script appended to the render output; its bootstrap declares that records may still be pending (`_$HY.p`), and when `hydrate()` runs while the parser is still working and no record has landed, it parks its start until the first record write or `DOMContentLoaded`, whichever comes first — the parser finishing is the proof that no records script is coming. Deferred and module (non-`async`) entries run after parsing and never wait; islands integrations that only ship the bootstrap and hydrate after load are unaffected. `hydrate()` still returns its dispose function synchronously, and disposing cancels a parked start.
32
+
31
33
### Consuming the stream: `pipe`, `pipeTo`, `readable`
32
34
33
35
`renderToStream` returns a result with three consumption surfaces — **exactly one may be used per render** (a second consumer throws with a directed message):
0 commit comments