# Server-Side Rendering

> Render a route to HTML on the server, including how request data and loader results reach the renderer.

Source: [https://askrjs.com/docs/rendering/server-side-rendering](https://askrjs.com/docs/rendering/server-side-rendering)

Status: stable. Packages: @askrjs/askr/ssr.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Example

```tsx
const html = renderToString({
  registry,
  url: request.url,
});
```

## Render requests

`resolveRequest` from `@askrjs/askr/ssr` takes a URL plus the same explicit `RouteRegistry` used by boot and SSG, returning a `RouteRequestResult`. `renderRouteRequest` goes a step further and actually renders: given `url`, `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.

## Documentation navigation

[Previous](https://askrjs.com/docs/rendering/client-and-islands/index.md) | [Next](https://askrjs.com/docs/rendering/streaming/index.md)
