# @askrjs/askr/ssr

> Published API exports for @askrjs/askr/ssr.

Source: [https://askrjs.com/docs/reference/api/askr/ssr](https://askrjs.com/docs/reference/api/askr/ssr)

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.

## Exports

This entrypoint publishes 22 exports from the declarations shipped by @askrjs/askr.

### `createRenderContext`

```ts
createRenderContext: (seed?: number, opts?: { url?: string; data?: SSRData; params?: Record<string, string>; routes?: readonly Route[]; routeAuth?: RouteAuthOptions; authContext?: AuthContext; basePath?: string; signal?: AbortSignal; dataRuntime?: unknown; mode?: "ssr" | "spa"; queryPrefetch?: QueryPrefetchContext; framework?: Readonly<Record<string, unknown>>; envelope?: PageRenderEnvelope; cspNonce?: string; }) => RenderContext
```

Build a fresh SSR render context (data cache, routes, seed) for a render pass.

### `DocumentRenderArgs`

```ts
DocumentRenderArgs: any
```

Arguments passed to a {@link DocumentRenderer}: the rendered app HTML and its context.

- `appHtml`: appHtml: string;

- `context`: context: DocumentRenderContext;

### `DocumentRenderContext`

```ts
DocumentRenderContext: any
```

Request/render metadata passed to a {@link DocumentRenderer}.

- `mode`: mode: 'ssr' | 'ssg';

- `url`: url: string;

- `pathname`: pathname: string;

- `search`: search: string;

- `hash`: hash: string;

- `params`: params: Record<string, string>;

- `data`: data?: SSRData;

- `seed`: seed: number;

- `route`: route: DocumentRenderRoute;

- `cspNonce`: cspNonce?: string;

- `styles`: styles?: readonly SSRStyleRegistration[];

### `DocumentRenderer`

```ts
DocumentRenderer: (args: DocumentRenderArgs) => string
```

Wraps rendered app HTML in a full document (`<html>`, `<head>`, etc.) for SSR/SSG output.

### `getRenderContext`

```ts
getRenderContext: () => RenderContext | null
```

Get the current render context.
Returns null if not inside a render.

### `renderResolvedToStringSync`

```ts
renderResolvedToStringSync: (opts: { url: string; registry: RouteRegistry; handler: RouteHandler; params?: Record<string, string>; options?: { seed?: number; data?: SSRData; dataRuntime?: DataRuntime; envelope?: PageRenderEnvelope; cspNonce?: string; }; }) => string
```

Synchronously render an already-resolved route handler to an HTML string.

### `renderRouteRequest`

```ts
renderRouteRequest: (options: RenderRouteRequestOptions) => Promise<RenderRouteRequestResult>
```

Resolve and render a route request for SSR, streaming the body when possible.

### `RenderRouteRequestOptions`

```ts
RenderRouteRequestOptions: any
```

Options for {@link renderRouteRequest} and {@link renderRouteRequestToString}.

- `url`: url: string;

- `registry`: registry: RouteRegistry;

- `auth`: auth?: RouteAuthOptions;

- `authContext`: authContext?: AuthContext;

- `request`: request?: Request;

- `signal`: signal?: AbortSignal;

- `seed`: seed?: number;

- `data`: data?: SSRData;

- `framework`: Askr-owned state retained independently from route loader output.

- `dataRuntime`: dataRuntime?: DataRuntime;

- `queryPrefetch`: queryPrefetch?: QueryPrefetchContext;

- `queryRegistry`: queryRegistry?: ServerQueryRegistry;

- `telemetry`: telemetry?: CoreTelemetry;

- `cspNonce`: cspNonce?: string;

### `RenderRouteRequestResult`

```ts
RenderRouteRequestResult: {
  kind: 'render';
  html: string;
  stream?: ReadableStream<Uint8Array>;
  styles: readonly SSRStyleRegistration[];
  params: Record<string, string>;
  record?: RouteRecord;
} | AccessRedirectDecision | AccessDenyDecision | {
  kind: 'no-match';
}
```

Outcome of rendering a route request for SSR: a render, redirect, deny, or no-match.

### `renderRouteRequestToString`

```ts
renderRouteRequestToString: (options: RenderRouteRequestOptions) => Promise<RenderRouteRequestResult>
```

Resolve and render a route request for SSR, always fully buffering the HTML.

### `renderToStream`

```ts
renderToStream: (opts: RouteStreamOptions) => void
```

Stream a route request's rendered HTML to the response sink described by `opts`.

### `renderToString`

```ts
renderToString: { (component: (props?: Record<string, unknown>) => VNode | JSXElement | string | number | null): string; (opts: RouteRenderOptions): string; }
```

Render a component or route request to a complete HTML string, synchronously.

### `renderToStringSync`

```ts
renderToStringSync: (component: (props?: Record<string, unknown>) => VNode | JSXElement | string | number | boolean | null | undefined, props?: Record<string, unknown>, options?: { seed?: number; data?: SSRData; envelope?: PageRenderEnvelope; cspNonce?: string; authContext?: import("@askrjs/auth").AuthContext; onContext?: (ctx: RenderContext) => void; }) => string
```

Synchronously render a component to an HTML string, without route resolution.

### `resolveRequest`

```ts
resolveRequest: (opts: { url: string; registry: RouteRegistry; auth?: RouteAuthOptions; authContext?: AuthContext; request?: Request; signal?: AbortSignal; }) => Promise<RouteRequestResult>
```

Resolve a URL against a route registry for SSR, applying auth/policies before render.

### `SSRComponent`

```ts
SSRComponent: (props: Props, context?: {
  signal?: AbortSignal;
  ssr?: RenderContext;
}) => VNode | JSXElement | string | number | boolean | null | undefined
```

Component function signature for SSR.
Components receive props and an optional context with signal and SSR context.

### `SSRDataMissingError`

```ts
SSRDataMissingError: typeof SSRDataMissingError
```

Common call contracts: SSR error types

- `code`: readonly code = "SSR_DATA_MISSING";

### `SSRRoute`

```ts
SSRRoute: {
  path: string;
  handler: RouteHandler;
  namespace?: string;
}
```

A single path-to-handler route binding accepted by low-level SSR route rendering.

### `SSRStyleRegistration`

```ts
SSRStyleRegistration: any
```

Styles produced while rendering a request, kept with that request's SSR context.

- `id`: id: string;

- `cssText`: cssText: string;

### `SSRStyleRegistrationValidation`

```ts
SSRStyleRegistrationValidation: 'warn' | 'error' | 'off'
```

How to react when SSR styles were registered but not included in the rendered document.

### `VNode`

```ts
VNode: {
  type: string | SSRComponent | symbol;
  props?: Props;
  children?: unknown[];
  key?: string | number | null;
}
```

VNode representation for SSR rendering

### `withRenderContext`

```ts
withRenderContext: <T>(ctx: RenderContext, fn: () => T) => T
```

Run a function with the given render context.
Concurrency-safe in Node.js via AsyncLocalStorage.

### `withRenderContextAsync`

```ts
withRenderContextAsync: <T>(ctx: RenderContext, fn: () => T | PromiseLike<T>) => Promise<T>
```

Run `fn` with `ctx` as the active SSR render context, using async-local storage.

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/askr/actions/index.md) | [Next](https://askrjs.com/docs/reference/api/askr/ssg/index.md)
