Rendering & SSR

renderToString

Renders a component tree synchronously to an HTML string. Async reads inside <Loading> boundaries emit their fallback content; for full-graph resolution use renderToStringAsync instead.

Pair the returned HTML with hydrate() on the client.


Import

import { renderToString } from "@solidjs/web";

Type signature

function renderToString<T>(
fn: () => T,
options?: {
nonce?: string;
renderId?: string;
noScripts?: boolean;
plugins?: any[];
manifest?: Record<
string,
{
file: string;
css?: string[];
isEntry?: boolean;
isDynamicEntry?: boolean;
imports?: string[];
}
>;
onError?: (err: any) => void;
}
): string;

Examples

import { renderToString } from "@solidjs/web";
const html = renderToString(() => <App />);
res.send(
`<!doctype html><html><body><div id="root">${html}</div></body></html>`
);
Last updated: 7/4/26, 6:21 PMEdit this pageReport an issue with this page