Skip to main content
zerotal

Documentation


Documentation / @zerotal/inertia / inertiaStream

Function: inertiaStream()

inertiaStream(component, props?): Promise<void>

Defined in: inertia/src/inertia.ts:162

Render an Inertia page server-side and return a streaming HTML Response.

Splits the HTML template at <!-- @inertia --> and writes the server-rendered component between the prefix and suffix, improving TTFB over inertia() since the browser can start parsing the <head> before the component is sent.

Framework-aware: React pages (.tsx) stream chunk-by-chunk via react-dom/server's renderToReadableStream; Vue pages (.vue) are rendered to a string via @inertiajs/vue3's SSR mode (head tags injected into <head>) and flushed after the prefix. The component is resolved from <cwd>/<inertia.pagesDir>/<component>.{vue,tsx} (defaults to resources/js/pages).

Like inertia, this reads the current request from RequestContext and writes the streaming Response onto ctx.response as a side effect (returns void). Reach it from a controller via Inertia.stream(...).

Parameters

component

string

Page component name (path relative to the pages dir, no extension), e.g. "Posts/Show".

props?

Record<string, unknown> = {}

Props passed to the page; may include prop wrappers (optional/defer/merge/…).

Returns

Promise<void>

Throws

InertiaTemplateNotLoadedError When the HTML template has not been loaded (InertiaProvider not registered).

Throws

InvalidComponentError When the component name contains path-traversal sequences.

Example

async show(http: HttpContext): Promise<void> {
  const post = await Post.findOrFail(http.params.id);
  return Inertia.stream('Posts/Show', { post });
}