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 21 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.

escapeHtmltype

escapeHtml: (value: unknown) => string

Escape a string for interpolation into a hand-written HTML document template, either as text content or inside a quoted attribute value. Replaces &, <, >, " and ' with character references. Use it for every request-derived value a document renderer interpolates, such as context.pathname, context.params or loader data. Do not use it for appHtml, which is already rendered markup, or inside <script>/<style> raw text. null and undefined render as an empty string; other values are converted with String().

getRenderContexttype

getRenderContext: () => RenderContext | null

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

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?: AuthContext; onContext?: (ctx: RenderContext) => void; }) => string

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

SSRAccessDecisionErrortype

SSRAccessDecisionError: typeof SSRAccessDecisionError

Thrown by synchronous route SSR (renderToString()/renderToStream()) when route auth or a policy redirects or denies the request. Nothing is rendered; send decision as the HTTP response (for example a 302 to decision.to, or decision.status).

code
readonly code = 'SSR_ACCESS_DECISION';
decision
readonly decision: AccessRedirectDecision | AccessDenyDecision;

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';

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.