@gluonjs/ssr / packages/ssr/src / renderProgressively
Function: renderProgressively()
renderProgressively(
value,options?):AsyncGenerator<ProgressiveRenderChunk>
Emits fallbacks in the shell and resolved async boundaries as ordered patch records.
Parameters
value
options?
Returns
AsyncGenerator<ProgressiveRenderChunk>
Example
Emit an immediate fallback shell followed by ordered resolved async-boundary patches, with caller-owned abort support:
import { html } from '@gluonjs/core';
import {
SsrRenderError,
prepareForHydration,
renderProgressively,
renderToChunks,
renderToString,
type PreparedHydration,
type ProgressiveRenderChunk,
type ProgressiveRenderOptions,
} from '@gluonjs/ssr';
const product = html`<article><h1>Orbit lamp</h1><p>€129</p></article>`;
const prepared: PreparedHydration = await prepareForHydration(product);
const complete = await renderToString(prepared.value);
let chunked = '';
for await (const chunk of renderToChunks(prepared.value)) chunked += chunk;
const controller = new AbortController();
const options = { signal: controller.signal } satisfies ProgressiveRenderOptions;
for await (const chunk of renderProgressively(prepared.value, options)) {
const progressive: ProgressiveRenderChunk = chunk;
console.log(progressive.kind, progressive.html);
}
if (complete !== chunked) throw new SsrRenderError('GLUON_SSR_INVALID_VALUE', 'Chunk output changed.');