renderToStream
Edit this pagerenderToStream streams server-rendered HTML and continues writing async content as it resolves.
Import
import { renderToStream } from "solid-js/web";Type
function renderToStream<T>( fn: () => T, options?: { nonce?: string; renderId?: string; onCompleteShell?: (info: { write: (v: string) => void }) => void; onCompleteAll?: (info: { write: (v: string) => void }) => void; }): { pipe: (writable: { write: (v: string) => void }) => void; pipeTo: (writable: WritableStream) => void;};Parameters
fn
- Type:
() => T
Function that returns the root output to render.
options
nonce
- Type:
string
Nonce applied to inline scripts emitted during rendering.
renderId
- Type:
string
Identifier used to namespace the render output.
onCompleteShell
- Type:
(info: { write: (v: string) => void }) => void
Callback invoked when the shell is ready to flush.
onCompleteAll
- Type:
(info: { write: (v: string) => void }) => void
Callback invoked after all server suspense boundaries have settled.
Return value
- Type:
{ pipe: ..., pipeTo: ... }
Streaming controller with pipe and pipeTo methods.
Behavior
renderToStreamis a server rendering API and is unsupported in browser bundles.- It renders the shell first, including suspense fallback content, and can flush that output before later async fragments and serialized data stream as resources resolve.
onCompleteShellandonCompleteAllreceive awrite()helper for injecting additional output into the stream.pipewrites to Node-style writable targets.pipeTowrites to aWritableStream.
Examples
pipe
import { renderToStream } from "solid-js/web";
renderToStream(() => <App />).pipe(response);pipeTo
import { renderToStream } from "solid-js/web";
const { writable } = new TransformStream();renderToStream(() => <App />).pipeTo(writable);