lit-ui-router-ssr / prerender
Function: prerender()
function prerender(options): Promise<PrerenderResult>;Defined in: packages/lit-ui-router-ssr/src/prerender.ts:444
Emits a static site from a mount table's verdicts: a shell verdict becomes <subpath>/index.html, a redirect becomes a rules line and no page, and the otherwise projection becomes the 404 document.
The router is provided on the render root for context-request and scoped with withRouterSync around each render, so a template's <ui-router> descendants and its sref attribute directives read the same router. Renders run one at a time: the scope is a module slot, so there is nothing to parallelise.
A rendered page opens on its hydration signature: a JSON data block, <script type="application/json" data-lit-ui-router-ssr>, naming this package's version and the state and parameter values the router stood on, which hydrateRoot() reads before it touches the document. A renderShell that returns a string is written as-is, with no signature, so the client renders it cold.
Pages are rendered with deferHydration, so every custom element one holds carries defer-hydration and renders nothing until hydrateRoot()'s walk reaches it on the client. A property binding emits only its part marker: the property is set when the page hydrates, so what an element must show on the served page arrives as an attribute or as children.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | PrerenderOptions | the mount table, the router, the paths, and the hooks |
Returns
Promise<PrerenderResult>
what was emitted, planned or written
Throws
an Error when neither mounts nor resolver is supplied
Example
const result = await prerender({
mounts,
router,
outDir: 'dist',
paths: ['/', '/sheet/7B', '/legacy'],
renderShell: async (verdict, { path }) => {
await settle(router, path);
return page();
},
document: (body, { path }) => fillShell(titles.get(path), body),
});