StreamOptions
Options of renderToStream.
Options of renderToStream.
Import#
ts
import type { StreamOptions } from "@shadow-js/web/server";
Signature#
ts
interface StreamOptions {
/**
* Prefix of every hydration key: letters, digits, `_` and `-` only. Pass the same id to `hydrate()`.
* @default "0"
*/
readonly renderId?: string;
/**
* CSP nonce for the inline swap scripts. Characters outside letters, digits, `+`, `/`, `=`, `_` and
* `-` are removed before it is written.
* @default undefined (the scripts get no nonce attribute)
*/
readonly nonce?: string;
/**
* Upper bound for the whole stream, in milliseconds, a positive finite number. When it runs out, the stream errors with an
* `SsrError` whose `code` is `SSR_TIMEOUT`.
* @default 30000
*/
readonly timeoutMs?: number;
/**
* Aborts the render: the stream errors with the signal's reason and every pending fetch is abandoned.
* @default undefined (the render is bounded only by `timeoutMs`)
*/
readonly signal?: AbortSignal;
/**
* Collects the tags `useHead`, `<Title>`, ... register while the shell renders (see
* `createServerHead`).
* @default undefined (head tags are not collected)
*/
readonly head?: ServerHead;
/**
* Called with the shell markup as soon as it is ready, before it is enqueued: the moment to write
* the document head and choose the response status.
* @default undefined (no callback)
*/
readonly onShellReady?: (shell: string) => void;
/**
* Collects the markup of the portals the stream produces (see {@link createServerPortals}). The stream
* does not write it: once the stream has ended, emit `portals.html()` at the end of `<body>`.
* @default undefined (a portal renders nothing on the server)
*/
readonly portals?: ServerPortals;
/**
* Receives an error an `ErrorBoundary` of the stream caught, once per caught error. An error in the shell
* happens before the first chunk, so the caller can still choose the response status; an error in a later
* boundary happens after the shell and changes only that boundary (its fallback stays).
* @default undefined (caught errors are not reported)
*/
readonly onCaughtError?: (error: unknown) => void;
/**
* Receives an error no boundary took. With it the stream does not error on that error and the markup lacks
* the part that failed.
* @default undefined (the error ends the stream in its `error` state)
*/
readonly onUncaughtError?: (error: unknown) => void;
}
Members#
| Name | Type | Description |
|---|---|---|
renderId? |
readonly renderId?: string |
Prefix of every hydration key: letters, digits, _ and - only. Pass the same id to hydrate(). |
nonce? |
readonly nonce?: string |
CSP nonce for the inline swap scripts. Characters outside letters, digits, +, /, =, _ and - are removed before it is written. |
timeoutMs? |
readonly timeoutMs?: number |
Upper bound for the whole stream, in milliseconds, a positive finite number. When it runs out, the stream errors with an SsrError whose code is SSR_TIMEOUT. |
signal? |
readonly signal?: AbortSignal |
Aborts the render: the stream errors with the signal's reason and every pending fetch is abandoned. |
head? |
readonly head?: ServerHead |
Collects the tags useHead, <Title>, ... register while the shell renders (see createServerHead). |
onShellReady? |
readonly onShellReady?: (shell: string) => void |
Called with the shell markup as soon as it is ready, before it is enqueued: the moment to write the document head and choose the response status. |
portals? |
readonly portals?: ServerPortals |
Collects the markup of the portals the stream produces (see createServerPortals). The stream does not write it: once the stream has ended, emit portals.html() at the end of <body>. |
onCaughtError? |
readonly onCaughtError?: (error: unknown) => void |
Receives an error an ErrorBoundary of the stream caught, once per caught error. An error in the shell happens before the first chunk, so the caller can still choose the response status; an error in a later boundary happens after the shell and changes only that boundary (its fallback stays). |
onUncaughtError? |
readonly onUncaughtError?: (error: unknown) => void |
Receives an error no boundary took. With it the stream does not error on that error and the markup lacks the part that failed. |