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 ccfc7ea
Browse filesBrowse the repository at this point in the historyBrowse files
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]>
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).
Reject `renderToStream` thenable consumers with `signal.reason` when its `signal` aborts, including consumers registered after cancellation. Render failures still resolve with the available HTML.
-`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)).
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
@@ -77,6 +77,8 @@ export function handler(request: Request): Response {
77
77
}
78
78
```
79
79
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
+
80
82
`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.
81
83
82
84
### The request event
@@ -357,7 +359,7 @@ export function handleRequest(request: Request): Promise<Response> {
357
359
-**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()`).
358
360
-**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).
359
361
-**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.
361
363
-`options.transformChunk(chunk)` rewrites each outgoing HTML chunk — the seam handlers use for entry-script injection and doctype prefixes.
362
364
363
365
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.
0 commit comments