Askr documentation
Generated API snapshot

@askrjs/askr/ssr

Exports from the declarations published in @askrjs/askr. Signatures reflect the published artifact.

Exports

This entrypoint publishes 22 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

createRenderContexttype

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.

DocumentRenderArgstype

DocumentRenderArgs: any

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

appHtml
appHtml: string;
context
context: DocumentRenderContext;

DocumentRenderContexttype

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[];

DocumentRenderertype

DocumentRenderer: (args: DocumentRenderArgs) => string

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

getRenderContexttype

getRenderContext: () => RenderContext | null

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

renderResolvedToStringSynctype

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.

renderRouteRequesttype

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

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

RenderRouteRequestOptionstype

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;

RenderRouteRequestResulttype

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.

renderRouteRequestToStringtype

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

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

renderToStreamtype

renderToStream: (opts: RouteStreamOptions) => void

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

renderToStringtype

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.

renderToStringSynctype

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.

resolveRequesttype

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.

SSRComponenttype

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.

SSRDataMissingErrortype

SSRDataMissingError: typeof SSRDataMissingError

Common call contracts: SSR error types

code
readonly code = "SSR_DATA_MISSING";

SSRRoutetype

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

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

SSRStyleRegistrationtype

SSRStyleRegistration: any

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

id
id: string;
cssText
cssText: string;

SSRStyleRegistrationValidationtype

SSRStyleRegistrationValidation: 'warn' | 'error' | 'off'

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

VNodetype

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

VNode representation for SSR rendering

withRenderContexttype

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

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

withRenderContextAsynctype

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

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