Skip to content

Commit ccfc7ea

Browse files
ryansolidclaudeeverton-dgn
authored
fix(web): settle renderToStream's awaited form and pipeTo when the signal aborts (#4654)
* fix(web): settle renderToStream's awaited form and pipeTo when the signal aborts A `signal` abort winds the render down as a disconnect, and a disconnect skipped the consumer completions the failure wind-down runs. So `await renderToStream(...)` and `pipeTo`'s promise never settled when the source never landed, or when the signal was already aborted. The wind-down now runs every consumer's completion with a `gone` flag. A disconnect still leaves the sink alone, but the promises settle: the awaited form resolves with the HTML it produced and never rejects. Fixes #4646. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * test(web): pass the event argument to createSSRResponse in the #4646 spec Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * fix(web): reject render thenables on signal cancellation * fix(web): reject the awaited form from the abort wind-down; pipe forms only settle Integrates #4649 with #4654's wind-down. On this branch the signal's disconnect wind-down already completes every registered consumer, so the awaited form's completion resolved before #4649's `onCancelled` hook could reject it. Fold the rejection into that completion instead: `onAbort` marks `cancelled` before the wind-down, and the thenable's `onFailure` completion rejects with `signal.reason` when it is set (at registration too, for an abort before `then`). The separate `onCancelled` chain is dropped. `pipe`/`pipeTo` keep #4654's behaviour: nothing more is written to or ends the sink, `pipeTo`'s promise resolves, `createSSRResponse` still answers a pre-shell abort with a bodyless 500. The #4646 spec now expects the awaited form to reject with signal.reason; the signal JSDoc (server.ts, server-mock.ts), 12-ssr-http.md and the observability sketch state the split. 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): end the streaming forms cleanly when the signal aborts The ruling for the pipe forms is "stop writing and close cleanly". Until now a signal abort only settled their promises: the `readable` view never closed (before or after the shell), a post-shell `createSSRResponse` body (status 200) never ended, and a raw `pipe` sink was never ended. All of this was already the case on next. The wind-down completions now receive the `abandon` reason instead of a boolean. On `"signal"` the sink is still alive, so: - `pipeTo` closes its writable after the writes it already handed over (whatever was still coalescing is dropped) and resolves. This also closes `readable`, which is built on it. - `pipe` ends the raw sink directly, because the live wrapper is guarded off once disconnected. A post-shell `createSSRResponse` body therefore closes, and a pre-shell abort still resolves with the bodyless 500. A dead sink (`"sink"`, `"consumer"`) is still left alone. `onError` and `onCompleteAll` stay uncalled. The frame stream's pipe sink is unaffected: its `end` is guarded by `ended`, which is set before its quiet abort. The #4646 spec now covers {already aborted, before the shell, after the shell} x {source settles later, never settles} for await, pipeTo, readable, pipe and createSSRResponse, plus two awaits on a source that rejects later (nothing escapes) and an abort after completion. Updated the server-diagnostics pin that asserted the sink is "never touched again, not even to end it" (now ended once), and updated the `signal` JSDoc, 12-ssr-http.md and the changeset to match. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * test(web): pin the late-Location script written after an abort (#4646) The abort-driven end() under createSSRResponse still appends the client-side redirect script for a Location set after the head went out. Docs name it as the one write after an abort. 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]>
1 parent f53d927 commit ccfc7ea

10 files changed

Lines changed: 469 additions & 52 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Aborting `renderToStream`'s `signal` now settles and ends every streaming consumer. Before, the promise from `pipeTo` could stay pending forever after an abort, the `readable` view and a `createSSRResponse` body never closed, and a `pipe` sink was never ended, which kept the request alive. Now nothing more is written and each surface ends cleanly, as a close and not an error, since the bytes already sent stay sent: `pipe` ends its sink, `pipeTo` closes its writable and resolves without rejecting, and `readable` closes. `createSSRResponse` ends its `200` body after the shell and still resolves with a bodyless `500` before it. `onError` and `onCompleteAll` are not called. The awaited form rejects with `signal.reason` (see the companion changeset) (#4646).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Reject `renderToStream` thenable consumers with `signal.reason` when its `signal` aborts, including consumers registered after cancellation. Render failures still resolve with the available HTML.

‎documentation/plans/stage8-connection-transport.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ component ("summarize the room") for the bounded contrast.
389389
`pumpIterator`. Pinned in `frame-teardown.spec.tsx` (body cancel; request
390390
abort ends the body; already-aborted request renders nothing; through
391391
the handler; flight response) and `server-diagnostics.spec.tsx` (the
392-
document face: reason `signal`, sink never touched again).
392+
document face: reason `signal`, sink ended once and never written after the abort;
393+
#4646).
393394

394395
### B2 — frames consume `live`
395396

‎documentation/proposals/production-observability-sketch.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ Verified against `next` (file:line as of 2026-09-06):
510510
Failure modes the server runtime already handles but reports nowhere
511511
structured — each is a candidate finding (§10):
512512

513-
- `await renderToStream(...)` **never rejects**; render errors go to
513+
- `await renderToStream(...)` **never rejects for a render error**
514+
(only an aborted `signal` rejects it, with `signal.reason`, #4646); render errors go to
514515
`onError` and the promise still resolves HTML (`server.ts:1579–1584`).
515516
- Stream **disconnect/abandon** → silent wind-down (`:1634–1644`,
516517
`:1698–1714`).

‎documentation/solid-2.0/12-ssr-http.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Client (`@solidjs/web` in the browser):
2424
Server (`@solidjs/web` under the `node`/`deno`/`worker` conditions):
2525

2626
- `renderToString(() => <App />)` — synchronous; async boundaries render their fallbacks.
27-
- `renderToStream(() => <App />, options?)` — the streaming renderer: the shell flushes first, and each async boundary streams its resolved fragment plus the activation script that swaps it in. A primitive marked `deferStream: true` (RFC 05) holds the shell flush until its first value resolves instead of letting the enclosing `<Loading>` fallback into the HTML. The returned stream is also a thenable: `await renderToStream(...)` resolves once the tree settles with the fully-resolved HTML string — the settled-string form of the render (what `renderToStringAsync` was before its removal).
27+
- `renderToStream(() => <App />, options?)` — the streaming renderer: the shell flushes first, and each async boundary streams its resolved fragment plus the activation script that swaps it in. A primitive marked `deferStream: true` (RFC 05) holds the shell flush until its first value resolves instead of letting the enclosing `<Loading>` fallback into the HTML. The returned stream is also a thenable: `await renderToStream(...)` resolves once the tree settles with the fully-resolved HTML string — the settled-string form of the render (what `renderToStringAsync` was before its removal). Render errors go to `onError` and the promise still resolves with whatever HTML the render produced; the one rejection is the `signal` option aborting, which rejects the awaited form with `signal.reason` ([#4646](https://github.com/solidjs/solid/issues/4646)).
2828

2929
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.
3030

@@ -77,6 +77,8 @@ export function handler(request: Request): Response {
7777
}
7878
```
7979

80+
If the `signal` option aborts, every surface stops writing (except the late-`Location` script `createSSRResponse` appends; see below) and ends cleanly: a close, not an error, since the bytes already sent stay sent. `pipe` ends its sink, `pipeTo` closes its writable and its promise resolves (it does not reject), and `readable` closes. Neither `onError` nor `onCompleteAll` is called. Under `createSSRResponse`, an abort after the shell ends the `200` body; one before the shell still resolves with a bodyless `500` (see below). Only the awaited form rejects, with `signal.reason` ([#4646](https://github.com/solidjs/solid/issues/4646)).
81+
8082
`readable` exists because web-standard servers (workers, Deno, fetch-shaped Node frameworks) construct a `Response` from a `ReadableStream` — with only `pipeTo`, every integration re-derived the same `TransformStream` dance by hand.
8183

8284
### The request event
@@ -357,7 +359,7 @@ export function handleRequest(request: Request): Promise<Response> {
357359
- **At shell flush** — the moment the head freezes — the stub is `committed` and its status/headers are merged over `options.responseInit` (`Set-Cookie` values survive as separate entries; `Server-Timing` folds entry by entry; `content-type` defaults to `text/html; charset=utf-8`). The commit is also where the request's trace reaches the head (`Server-Timing: traceparent;desc="…"` — see `getTraceContext()`).
358360
- **A `Location` present before the flush** becomes a real redirect instead of an HTML response: bodyless, carrying the stub’s cookies, with the status from `getExpectedRedirectStatus` (also exported — the stub’s own status when it is a redirect status, `302` otherwise, because a status set for the page render doesn’t describe the redirect that preempts it).
359361
- **A `Location` set after the flush** can only be honored client-side: stream completion appends `<script>window.location=…</script>` before closing, carrying `options.nonce` so a strict `script-src` CSP doesn’t block it.
360-
- **A render that ends before the flush** (it failed, which `onError` hears as `handling: "failed"`, or its `signal` aborted) produced no page: the promise resolves with a bodyless `500` (a `Location` already on the stub still redirects) and the stub is committed. It never rejects.
362+
- **A render that ends before the flush** (it failed, which `onError` hears as `handling: "failed"`, or its `signal` aborted) produced no page: the promise resolves with a bodyless `500` (a `Location` already on the stub still redirects) and the stub is committed. It never rejects. A `signal` abort after the flush ends the streamed body cleanly instead, still appending the late-`Location` script.
361363
- `options.transformChunk(chunk)` rewrites each outgoing HTML chunk — the seam handlers use for entry-script injection and doctype prefixes.
362364

363365
String results return a `Response` synchronously; stream results return a promise that resolves at shell flush, so returning it from a fetch handler sends the head at the right moment by construction.

‎packages/web/src/server-mock.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ export function renderToStream<T>(
265265
* "signal"`); the one teardown handle for a host whose transport cannot
266266
* report a dead consumer through the sink or the readable view — pass
267267
* `request.signal`.
268+
* Awaiting the render rejects with `signal.reason` when this signal aborts;
269+
* the streaming forms stop writing and end cleanly — a close, not an
270+
* error, since bytes are already out: `pipe` ends its sink, `pipeTo`
271+
* closes its writable (after the writes already handed to it) and
272+
* resolves, and `readable` closes. `onError` and `onCompleteAll` are not
273+
* called (#4646).
268274
*/
269275
signal?: AbortSignal;
270276
}
@@ -273,7 +279,7 @@ export function renderToStream<T>(
273279
* Awaiting the stream resolves with the complete HTML once every boundary
274280
* settles — the fully-settled-string form of the render. Render errors
275281
* route through `onError` and the promise resolves with whatever HTML the
276-
* render produced; it never rejects.
282+
* render produced. Signal cancellation rejects with `signal.reason`.
277283
*/
278284
then<TResult1 = string, TResult2 = never>(
279285
onfulfilled?: ((html: string) => TResult1 | PromiseLike<TResult1>) | null,

0 commit comments

Comments
 (0)