Skip to content

Commit 5a83563

Browse files
claudeeverton-dgn
andcommitted
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
1 parent fbabcc4 commit 5a83563

6 files changed

Lines changed: 34 additions & 29 deletions

File tree

‎.changeset/stream-signal-abort-settles.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/web": patch
33
---
44

5-
Aborting `renderToStream`'s `signal` now settles the consumer promises. Before, `await renderToStream(...)` and the promise from `pipeTo` stayed pending forever after an abort, which kept the request alive. The awaited form now resolves with whatever HTML the render had produced, as it already does for a render failure, and still never rejects. `pipeTo`'s promise resolves. As before, nothing more is written to the sink (#4646).
5+
Aborting `renderToStream`'s `signal` now settles the consumer promises. Before, `await renderToStream(...)` and the promise from `pipeTo` stayed pending forever after an abort, which kept the request alive. `pipeTo`'s promise now resolves and, as before, nothing more is written to the sink: the bytes already sent stay sent, and `pipe`/`pipeTo` do not reject. The awaited form rejects with `signal.reason` (see the companion changeset) (#4646).

‎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: 2 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

@@ -63,7 +63,7 @@ What the callback does and does not tell you:
6363
`renderToStream` returns a result with three consumption surfaces — **exactly one may be used per render** (a second consumer throws with a directed message):
6464

6565
- `pipe(writable)` — Node-style writable streams.
66-
- `pipeTo(writable)` — web `WritableStream`; returns a promise that settles when the render has been fully written.
66+
- `pipeTo(writable)` — web `WritableStream`; returns a promise that settles when the render has been fully written. If the `signal` aborts, nothing more is written (the bytes already sent stay sent) and the promise resolves; it does not reject.
6767
- `readable` — a getter that builds a web `ReadableStream` internally and hands it back. The stream yields `Uint8Array` bytes, `Response`-body ready:
6868

6969
```tsx

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ 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.
268+
* Awaiting the render rejects with `signal.reason` when this signal aborts;
269+
* the streaming forms only settle: `pipeTo`'s promise resolves, and
270+
* neither `pipe` nor `pipeTo` writes to or ends the sink again (#4646).
269271
*/
270272
signal?: AbortSignal;
271273
}

‎packages/web/src/server.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,9 @@ export function renderToStream<T>(
20172017
* consumed by a proxy — this is the one teardown handle; pass
20182018
* `request.signal`. Idempotent with the sink and consumer paths: whichever
20192019
* fires first tears down, the rest are no-ops.
2020-
* Awaiting the render rejects with `signal.reason` when this signal aborts.
2020+
* Awaiting the render rejects with `signal.reason` when this signal aborts;
2021+
* the streaming forms only settle: `pipeTo`'s promise resolves, and
2022+
* neither `pipe` nor `pipeTo` writes to or ends the sink again (#4646).
20212023
*/
20222024
signal?: AbortSignal;
20232025
}
@@ -2121,7 +2123,8 @@ export function renderToStream(code, options = {}) {
21212123
// registration. A disconnect runs it too, with `gone` set: the sink is
21222124
// left alone, but a promise still waiting on the render — the awaited
21232125
// form, `pipeTo`, `createSSRResponse`'s shell (`SHELL_ABANDONED`) — must
2124-
// settle, or it hangs the caller the same way (#4646).
2126+
// settle, or it hangs the caller the same way (#4646): the awaited form
2127+
// rejects with `signal.reason` when the `signal` aborted, the rest resolve.
21252128
let disconnected = false;
21262129
let onFailed;
21272130
// What the render still hands the serializer once it is torn down: a
@@ -3151,14 +3154,15 @@ export function renderToStream(code, options = {}) {
31513154
// frame stream ending a plain response at its streaming bound (see
31523155
// frame-sink's `frameStream`) — not a client that left: no abandonment
31533156
// finding for it.
3157+
// `cancelled` is set before the wind-down runs: the awaited form's
3158+
// completion (see `then`) reads it to reject with `signal.reason` instead
3159+
// of resolving; the pipe paths only settle (#4646).
31543160
let cancelled = false;
3155-
let onCancelled;
31563161
const onAbort = signal
31573162
? () => {
31583163
if (dead) return;
31593164
cancelled = true;
31603165
abandon("signal", !!(signal.reason && signal.reason.quiet === true));
3161-
onCancelled && onCancelled();
31623166
}
31633167
: undefined;
31643168
// Dependency edges: the server's signal-naming hooks are installed while
@@ -3530,12 +3534,6 @@ export function renderToStream(code, options = {}) {
35303534
commitResponseStub(requestEvent.response, { event: requestEvent });
35313535
};
35323536
const p = new Promise((resolve, reject) => {
3533-
if (cancelled) return reject(signal.reason);
3534-
const previousCancelled = onCancelled;
3535-
onCancelled = () => {
3536-
previousCancelled && previousCancelled();
3537-
reject(signal.reason);
3538-
};
35393537
function complete() {
35403538
freezeHead();
35413539
dispose();
@@ -3556,8 +3554,10 @@ export function renderToStream(code, options = {}) {
35563554
// the render died, its teardown
35573555
// retracts the declarations as it always did, and the consumer
35583556
// keeps a writable head for whatever error response it builds
3559-
// around the partial HTML.
3560-
onFailure(() => resolve(tmp));
3557+
// around the partial HTML. The signal aborting runs the same
3558+
// wind-down (a disconnect) and rejects with its reason instead —
3559+
// at registration too, when it aborted before `then` (#4646).
3560+
onFailure(() => (cancelled ? reject(signal.reason) : resolve(tmp)));
35613561
function flush() {
35623562
allSettled(blockingPromises).then(awaited => {
35633563
scheduleFlush(() => {

‎packages/web/test/server/stream-signal-abort-settles-4646.spec.tsx‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55
* down as a disconnect, but a disconnect skipped the consumer completions
66
* the failure wind-down runs: `await renderToStream(...)` and `pipeTo`'s
77
* promise never settled, holding the request forever. The awaited form
8-
* resolves with whatever HTML the render produced and never rejects
9-
* (renderToStream's JSDoc; 12-ssr-http.md). A disconnect still leaves the
10-
* sink alone: nothing more is written to it.
8+
* rejects with `signal.reason` (renderToStream's `then` JSDoc; 12-ssr-http.md;
9+
* #4649). The streaming forms only settle: `pipeTo`'s promise resolves, and
10+
* a disconnect still leaves the sink alone — nothing more is written to it.
1111
*/
1212
import { describe, expect, test } from "vitest";
1313
import { renderToStream, createSSRResponse } from "@solidjs/web";
1414
import { createMemo } from "solid-js";
1515

1616
const sleep = (ms: number) => new Promise<void>(r => setTimeout(r, ms));
1717

18-
type Outcome = { state: "resolved"; value: unknown } | { state: "rejected" } | { state: "pending" };
18+
type Outcome =
19+
| { state: "resolved"; value: unknown }
20+
| { state: "rejected"; reason: unknown }
21+
| { state: "pending" };
1922
const outcome = (p: PromiseLike<unknown>): Promise<Outcome> =>
2023
Promise.race([
2124
Promise.resolve(p).then(
2225
value => ({ state: "resolved" as const, value }),
23-
() => ({ state: "rejected" as const })
26+
(reason: unknown) => ({ state: "rejected" as const, reason })
2427
),
2528
sleep(500).then(() => ({ state: "pending" as const }))
2629
]);
@@ -34,8 +37,7 @@ const App = (never: boolean) => () => {
3437
return <p>{m()}</p>;
3538
};
3639

37-
const start = (never: boolean, preAborted: boolean) => {
38-
const c = new AbortController();
40+
const start = (never: boolean, preAborted: boolean, c = new AbortController()) => {
3941
if (preAborted) c.abort(new Error("gone"));
4042
const r = renderToStream(App(never), { signal: c.signal, onError() {} });
4143
if (!preAborted) setTimeout(() => c.abort(new Error("client disconnected")), 20);
@@ -47,11 +49,11 @@ describe("renderToStream: aborting the signal settles the consumer (#4646)", ()
4749
const source = never ? "a source that never settles" : "a source that settles later";
4850
for (const preAborted of [false, true]) {
4951
const when = preAborted ? "already aborted" : "aborted mid-render";
50-
test(`await resolves, never rejects (${when}, ${source})`, async () => {
51-
const r = await outcome(start(never, preAborted));
52-
expect(r.state).toBe("resolved");
53-
expect(typeof (r as { value: unknown }).value).toBe("string");
54-
expect((r as { value: string }).value).not.toContain("loaded");
52+
test(`await rejects with signal.reason (${when}, ${source})`, async () => {
53+
const c = new AbortController();
54+
const r = await outcome(start(never, preAborted, c));
55+
expect(r.state).toBe("rejected");
56+
expect((r as { reason: unknown }).reason).toBe(c.signal.reason);
5557
});
5658

5759
test(`pipeTo's promise resolves and the writable gets nothing (${when}, ${source})`, async () => {

0 commit comments

Comments
 (0)