Rendering

renderToStream

Edit this page

renderToStream 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

  • renderToStream is 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.
  • onCompleteShell and onCompleteAll receive a write() helper for injecting additional output into the stream.
  • pipe writes to Node-style writable targets.
  • pipeTo writes to a WritableStream.

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);

Report an issue with this page