Перейти к содержанию

renderToStream

import { Aside } from "~/components/configurable/Aside";

renderToStream

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function renderToStream<T>(
  fn: () => T,
  options?: {
    nonce?: string;
    renderId?: string;
    onCompleteShell?: () => void;
    onCompleteAll?: () => void;
  }
): {
  pipe: (writable: { write: (v: string) => void }) => void;
  pipeTo: (writable: WritableStream) => void;
};

This method renders to a stream. It renders the content synchronously including any Suspense fallback placeholders, and then continues to stream the data and HTML from any async resource as it completes.

1
2
3
4
5
6
// node
renderToStream(App).pipe(res);

// web stream
const { readable, writable } = new TransformStream();
renderToStream(App).pipeTo(writable);

onCompleteShell fires when synchronous rendering is complete before writing the first flush to the stream out to the browser. onCompleteAll is called when all server Suspense boundaries have settled. renderId is used to namespace renders when having multiple top level roots.

Options

Name Type Description
nonce string The nonce to use for inline scripts.
renderId string The id to use for this render.
onCompleteShell () => void A callback that fires when the shell is complete.
onCompleteAll () => void A callback that fires when all Suspense boundaries have settled.

Комментарии