Skip to content

lit-ui-router-ssr / readHydrationSignature

Function: readHydrationSignature() ​

ts
function readHydrationSignature(container): HydrationSignature | null;

Defined in: packages/lit-ui-router-ssr/src/client.ts:487

Reads the hydration signature prerender() wrote ahead of the render a container holds: the version of this package that drew the document, and the state and parameter values it was drawn for.

The signature is a <script type="application/json" data-lit-ui-router-ssr> data block among the container's own children, so this reads no deeper than they are; the first one wins. It reads the same before and after a hydrateRoot that adopts, which leaves the block in place; one that returns false clears the container.

Only version is checked. state and params are whatever the block carries, so narrow them before use. Read it before hydrateRoot, which clears a container it does not adopt.

Parameters ​

ParameterTypeDescription
containerParentNodethe element the server's markup was written into

Returns ​

HydrationSignature | null

the signature, or null when the container holds none, or one that does not parse to an object with a string version

Example ​

ts
import { hydrateRoot, readHydrationSignature } from 'lit-ui-router-ssr/client';

await booted;
const { state } = readHydrationSignature(root) ?? {};
const drawnForBoot = state === router.globals.current.name;
const release = hydrateRoot(root, page(router));