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 5ae39fc
Browse filesBrowse the repository at this point in the historyBrowse files
authored
fix(web): reject a hydration key whose async value fails to serialize (#4647) (#4659)
* fix(web): reject a hydration key whose async value fails to serialize (#4647)
An async value that resolved to something seroval cannot serialize was
reported as `render/serialize` and the render completed, but the payload
declared the key's promise and never settled it, so the client's read
stayed pending forever. Per Ryan's ruling (2026-11-03), the hydration
serializer now rejects that promise with an error that says it is a
serialization failure and names the key. The hydrating read throws into
the nearest Errored, whose fallback replaces the server's content until
reset() or an input change reruns it as a client fetch.
Server-only: the change is in the hydration serializer.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
* fix(web): fail renders on late default serializer errors
* fix(web): split #4647 at the first flush: fail the render before it, reject the key after
Ryan's ruling on #4659 (2026-11-03): "failing ssr on failed serialization
feels reasonable otherwise we could be midstream." everton-dgn's #4650
(cherry-picked in the previous commit) fails the render on a late default
serializer failure. Limit that to failures before the first flush (an
awaited render, or a stream whose shell has not gone out yet, checked
again where the shell is about to be written), and keep the client-side
rejection of the key for failures after it, where the render completes.
Merges the two stream-async-serialize-failure-4647 specs (pre-flush cases
from #4650, midstream cases from #4659, plus a boundary value that fails
while the shell still waits on a blocker). Re-pins the #4242 writer case:
its failure lands before the shell, so the render fails. Updates the
`handling: "serialize"` contract in 12-ssr-http.md, the renderToStream
onError JSDoc, the serializer comment and both changesets.
Co-authored-by: Éverton Toffanetto <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
* fix(web): reject everything a midstream-failed write sent, not just its key (#4647)
- Move the rejection into an exported `rejectUnserializedKey`, passed only
by `renderToStream` as the hydration serializer's `late` (so
`renderToString` does not carry it), and drop the dead `started` flag.
- On a write that fails after the first flush, reject every promise and
throw into every stream that write already sent (a nested promise, an
async iterable's later items), not only a top-level thenable key.
- Drop the failed parse's indexes from the shared refs, so a second key on
the same value parses it again and rejects instead of resolving
`undefined` from a slot the client never filled.
- Hydration spec replays real recorded stream output
(errored-unserializable-4647.gen.spec.tsx) instead of a hand-written
payload.
- Docs: the serialize road's wire (a fixed message naming the key, all
builds); pins cite the dated maintainer ruling (2026-11-03).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: Éverton Toffanetto <[email protected]>
Fail `renderToStream` when an asynchronous value cannot be serialized after its key was handed to the default serializer, if that happens before the first flush (an awaited render, or before the shell went out). The render tears down without calling `onCompleteAll` and nothing is sent (#4647). Synchronous serialization failures and custom serializers keep their existing behavior.
`renderToStream`: an async value that resolves to something the serializer cannot handle after the first flush (midstream) now rejects its key on the client instead of leaving it pending forever (#4647) — and with it every promise or async iterable inside the value that already went out (a nested promise, an async iterable's later items), and every other key on the same value. The failure is still reported as `{ kind: "render", handling: "serialize" }` and the render completes; the payload settles the key's promise with an error that says it is a serialization failure and names the key (the failure's own text stays on the server). The hydrating read throws into the nearest `<Errored>`, whose fallback replaces the server-rendered content until `reset()` or an input change reruns the computation as a client fetch. With no `<Errored>` above, it is uncaught like any rejected key. Before the first flush the render fails instead (see the other changeset).
Copy file name to clipboardExpand all lines: documentation/solid-2.0/12-ssr-http.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,8 @@ Said plainly, `httpHeader` is a **shell-time API**. Headers declared by streamed
168
168
169
169
A render failure reaches the client on several roads: the error an `<Errored>` caught, serialized so the client hydrates the same fallback; a rejected async source serialized into the stream; a `<Loading>` fragment rejecting its `_fr` promise; a frame stream's error chunks. On every one of them the **non-dev** build hands the client a generic `Error` (`"Internal Server Error"`) in place of a plain thrown value — `message`, `cause` and own properties stay on the server — the same policy the server-function wire applies ([RFC 10](10-server-functions.md#thrown-errors-sanitized-by-default)). A `"use server"` function called in-process during a render never touches that wire, so without this the production page load leaked exactly what the RPC withheld ([#3468](https://github.com/solidjs/solid/issues/3468)).
170
170
171
+
One more road carries no thrown value at all: a hydration value that failed to serialize after the first flush ([#4647](https://github.com/solidjs/solid/issues/4647), maintainer ruling, 2026-11-03). Its key — and every promise or async iterable the failed value had already sent, nested ones included — rejects on the client with a fixed `Error` whose message names the key (`Serialization failed: the hydration value for key "…" could not be serialized on the server`), in **all** builds: the message carries no server data, and the serializer's own error stays on the server, with the error hook (`handling: "serialize"`). The reading computation throws it into the nearest `<Errored>` like any other rejected key. Before the first flush the render fails instead, so nothing reaches the client.
172
+
171
173
The boundary sanitizes _before_ rendering its fallback, and serializes the same replacement: the fallback is rendered on the server with the error and hydrates against the record, so the two must agree. A fallback that prints `err().message` therefore shows the generic message in production, as it would for a server-function failure. `markSafeError` is the escape hatch on both wires — a branded error passes through with its own properties. An Error reached as a _value_ (never thrown — a form's field errors, say) is data and passes as written.
172
174
173
175
The dev/prod line is the build variant: the `development` export condition's server artifacts keep full fidelity; the production and observe artifacts sanitize. The observe tier records each replacement once as `SERVER_ERROR_SANITIZED` with `data.source: "ssr"` (advisory; `data.error` the original, `data.wire` what replaced it), beside the `SSR_RENDER_ERROR_CONTAINED` finding that carries the failure itself — the server keeps the truth, the wire gets the generic.
- **Called once per error object per `kind` per request, at first sight** (per render when no request is in scope — never once per process: an error object reused across requests is heard, and mapped, by each), with where the failure was met. A direct server-function call that throws during SSR inside an `<Errored>` is heard twice, as `server-function` and then as `render`, so `kind: "render"` alone tells you a render failed; the wire value is the first one the hook returned. `kind: "render"` — `fallback` (an `<Errored>` rendered its fallback; `boundary` is its hydration id and `boundaryPath` its component labels — where the error was **met** — while `ownerPath` is where it was **thrown**, the labels up the owner chain it escaped, when the compiler emitted them), `client` (a `<Loading>` fragment rejected, the client re-renders the subtree — unless the `<Loading>` is all of an `<Errored>`'s content: that `<Errored>` draws its fallback into the fragment, reports `fallback`, and the hydrating client adopts it, [#4287](https://github.com/solidjs/solid/issues/4287)), `failed` (nothing contained it; the request fails — including a synchronous throw out of `renderToString` or `renderToStream`'s first pass, reported before it reaches the caller), `serialize` (a hydration value would not serialize and the render went on without it — reported for a render that passed `onError`, as seroval's own `onError` always was). `kind: "server-function"` — `thrown` (the body threw; `functionId`, and `direct: true` for an in-process call during SSR) or `channel` (a rejection or throw escaping through the result graph, the head already committed). `kind: "request"` is always `failed`: a failure that fails the request outside any render or server function the runtime reports (a middleware throw, a setup step), reported by the framework's request handler through `reportRequestFailure(error, event)`. A render failure, synchronous throws included, is reported as `render`, so a handler that catches one and passes it to `reportRequestFailure` adds nothing. It has no per-request tier, so only the ambient hook hears it. `event` is the request, when the failure happened inside one, and always for `kind: "request"`.
197
-
-**The return is the wire value**: rendered into the fallback, serialized for hydration, sent as the RPC error. `undefined` leaves the default policy in place (generic outside dev, fidelity in dev). A returned value is the author's intent — like a `wrapInvocation` mapping — and is not sanitized again; `markSafeError` is not needed on it. Ignored for `failed`and `serialize`, which have no wire. One road a mapping does not reach: a rejected async source's serialized rejection is encoded the moment the source rejects, ahead of the boundary, and carries the default policy's value; the hydrating client renders from the boundary's record, which carries the mapping.
198
+
- **Called once per error object per `kind` per request, at first sight** (per render when no request is in scope — never once per process: an error object reused across requests is heard, and mapped, by each), with where the failure was met. A direct server-function call that throws during SSR inside an `<Errored>` is heard twice, as `server-function` and then as `render`, so `kind: "render"` alone tells you a render failed; the wire value is the first one the hook returned. `kind: "render"` — `fallback` (an `<Errored>` rendered its fallback; `boundary` is its hydration id and `boundaryPath` its component labels — where the error was **met** — while `ownerPath` is where it was **thrown**, the labels up the owner chain it escaped, when the compiler emitted them), `client` (a `<Loading>` fragment rejected, the client re-renders the subtree — unless the `<Loading>` is all of an `<Errored>`'s content: that `<Errored>` draws its fallback into the fragment, reports `fallback`, and the hydrating client adopts it, [#4287](https://github.com/solidjs/solid/issues/4287)), `failed` (nothing contained it; the request fails — including a synchronous throw out of `renderToString` or `renderToStream`'s first pass, reported before it reaches the caller), `serialize` (a hydration value would not serialize — reported for a render that passed `onError`, as seroval's own `onError` always was. A value that fails as it is handed over never reaches the client, and the render goes on without it ([#4227](https://github.com/solidjs/solid/issues/4227)). An async source's landing that fails is a key the client already holds as pending, [#4647](https://github.com/solidjs/solid/issues/4647): **before the first flush** — an awaited `renderToStream`, or a stream whose shell has not gone out — the render **fails** like a rejection there: nothing is sent, `onCompleteAll` does not fire, and the hook hears only `serialize`; **after the first flush** (midstream, where the response cannot be failed cleanly) the key — and any promise or async iterable inside its value that already went out — rejects on the client with an error that says the value could not be serialized and names the key, so the reading computation throws into the nearest `<Errored>`, whose fallback replaces the server's content until `reset()` or an input change reruns it as a client fetch — uncaught like any rejected key with no `<Errored>` above — and the render completes. A custom `serializer`'s late failure is its own to settle; the render completes. `renderToString` refuses async values outright, so it has no late case). `kind: "server-function"` — `thrown` (the body threw; `functionId`, and `direct: true` for an in-process call during SSR) or `channel` (a rejection or throw escaping through the result graph, the head already committed). `kind: "request"` is always `failed`: a failure that fails the request outside any render or server function the runtime reports (a middleware throw, a setup step), reported by the framework's request handler through `reportRequestFailure(error, event)`. A render failure, synchronous throws included, is reported as `render`, so a handler that catches one and passes it to `reportRequestFailure` adds nothing. It has no per-request tier, so only the ambient hook hears it. `event` is the request, when the failure happened inside one, and always for `kind: "request"`.
199
+
-**The return is the wire value**: rendered into the fallback, serialized for hydration, sent as the RPC error. `undefined` leaves the default policy in place (generic outside dev, fidelity in dev). A returned value is the author's intent — like a `wrapInvocation` mapping — and is not sanitized again; `markSafeError` is not needed on it. Ignored for `failed`, which has no wire, and for `serialize`, whose only wire — the midstream key rejection ([#4647](https://github.com/solidjs/solid/issues/4647)) — is the fixed message naming the key, never the serializer's error or a mapping of it. One road a mapping does not reach: a rejected async source's serialized rejection is encoded the moment the source rejects, ahead of the boundary, and carries the default policy's value; the hydrating client renders from the boundary's record, which carries the mapping.
198
200
-**Once means once across roads.** A direct server-function call that throws during SSR is met first by the invocation (`kind: "server-function"`, `direct: true`) and then by the `<Errored>` that contains it; the boundary reuses the verdict — the same replacement in the fallback and the record — and does not report again. A `<Loading>` re-pull recurring the same throw is the same object, the same verdict. The observe tier keeps the multi-event picture (an `"invocation"` record _and_ an `SSR_RENDER_ERROR_CONTAINED` finding) for consumers that want it.
199
201
-**Two tiers, as `wrapInvocation` has.** Ambient: `configureServerErrors({ onError })`, once per process, registered on `globalThis` under a registered symbol so a bundled server build and an instrumented `--import`ed module share it — and the only tier that sees direct in-process calls. Per request, overriding it: `onError` on `renderToStream`/`renderToString`, and on `handleServerFunctionRequest` for the call it dispatches. A throwing hook is reported on the console and treated as silent. With no hook anywhere, a failure that fails the request goes to `console.error` — never silent. A synchronous render throw is the exception: it is rethrown to the caller, whose own handling (or `reportRequestFailure`) decides.
200
202
-**One listener, every failure.** A `renderToStream``onError` written for the old single-argument shape keeps working; it now hears every handled failure, not only the one that fails the request — filter on `context.handling === "failed"` for the old behaviour. The hook fires in every tier, dev included; only the _default_ mapping differs by tier.
0 commit comments