Skip to content

@gluonjs/core / packages/ssr/src / renderToString

Function: renderToString() ​

renderToString(value, options?): Promise<string>

Resolves all current async boundaries and returns deterministic HTML.

Parameters ​

value ​

TemplateValue

options? ​

RenderSerializationOptions = {}

Returns ​

Promise<string>

Example ​

Resolve a supported TemplateValue into deterministic hydration-marked HTML for a complete buffered response:

ts
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.');

Version-matched documentation. Examples are checked against the public package contracts.