Server-Side Rendering
Use server-side rendering with the current published Askr packages.
@askrjs/askr/ssr0.0.59
How to use server-side rendering
Start with this complete server-side rendering shape, then replace the example data and application service with your own.
- Import the published @askrjs/askr/ssr entrypoint.
- Keep server-side rendering configuration next to the component, route, or server composition root that owns it.
- Handle pending, unavailable, cancellation, and failure states, then verify the production path.
const result = await renderToString({
registry,
url: request.url,
});Render requests
`resolveRequest` from `@askrjs/askr/ssr` takes a URL plus a route source (`registry`, `manifest`, or a plain `routes` array) and matches it against your route table, returning a `RouteRequestResult`. `renderRouteRequest` goes a step further and actually renders: given `url`, `manifest`/`registry`, optional `auth`/`authContext`, and a `request`, it resolves to either a `{ kind: 'render', html, params, record }` result, an access redirect/deny decision, or `{ kind: 'no-match' }`.
Document composition
Pass a `document: DocumentRenderer` to wrap the rendered `appHtml` in your full page shell; it receives `DocumentRenderContext` with `mode: 'ssr'`, the resolved `pathname`, `search`, `hash`, `params`, and the render `seed`. `renderToStringSync` and `renderResolvedToStringSync` are the lower-level, synchronous entry points when you already have a component or a matched handler and just need an HTML string without going through full request resolution.
Data transfer
SSR renders happen inside a `RenderContext` (created by `createRenderContext`) that carries `data: SSRData`, `params`, `dataRuntime`, and a `queryPrefetch: QueryPrefetchContext` for server queries fetched ahead of render. That same context exposes `renderData` and `hydrationData` as `PageRenderEnvelope` objects — the mechanism by which data fetched on the server is serialized and handed to the client for hydration without a second round trip.
Operational boundaries
`renderRouteRequest` accepts a `signal: AbortSignal` so a slow render can be cancelled when the underlying request is aborted, and an optional `telemetry: CoreTelemetry` hook for instrumenting render duration. `SSRDataMissingError` (code `SSR_DATA_MISSING`) is thrown when a component expects server-provided data that wasn't supplied, giving you a distinct error to catch separately from generic render failures.