/**
* Pre-render handler definition for build-time rendering of route segments.
*
* Prerender wraps a handler so that in production (phase 2)
* it can be pre-rendered at build time and served as a static Flight payload.
* In dev mode (phase 1), it behaves as a normal handler — the handler runs
* on every request just like a regular path() handler.
*
* The $$id is auto-generated by the Vite exposeInternalIds plugin
* based on file path and export name. No manual naming required.
*
* @example
* ```ts
* // Static page — no params
* export const DocsPage = Prerender(async (ctx) => {
* return
Documentation
;
* });
*
* // Dynamic page — params first, handler second
* export const DocsArticle = Prerender(
* async () => [{ slug: "getting-started" }, { slug: "api-reference" }],
* async (ctx) => {
* return {ctx.params.slug}
;
* }
* );
* ```
*/
import type { ReactNode } from "react";
import type { Handler, HandlerContext } from "./types.js";
import type { Handle } from "./handle.js";
export interface PrerenderOptions {
/**
* Keep handler in server bundle for live fallback (default: false).
* false: handler replaced with stub, source-only APIs excluded from bundle.
* true: handler stays in bundle, unknown params render live at request time.
*/
passthrough?: boolean;
}
export interface BuildContext {
/** Params extracted from the route pattern (populated from getParams). */
params: TParams;
/** Push handle data (frozen into pre-rendered output at build time). */
use: (handle: Handle) => (data: T) => void;
/** Synthetic URL built from pattern + params (no real request). */
url: URL;
/** Pathname portion of the synthetic URL. */
pathname: string;
}
export interface PrerenderHandlerDefinition = any> {
readonly __brand: "prerenderHandler";
/** Auto-generated unique ID (injected by Vite plugin). */
$$id: string;
/** In dev mode, the actual handler function that path() can call. */
handler: Handler;
/** Returns the list of param objects to pre-render (dynamic routes). */
getParams?: () => Promise | TParams[];
/** Pre-render options. */
options?: PrerenderOptions;
}
export declare function Prerender = {}>(handler: (ctx: HandlerContext) => ReactNode | Promise, options?: PrerenderOptions, __injectedId?: string): PrerenderHandlerDefinition;
export declare function Prerender>(getParams: () => Promise | TParams[], handler: (ctx: HandlerContext) => ReactNode | Promise, options?: PrerenderOptions, __injectedId?: string): PrerenderHandlerDefinition;
/**
* Type guard to check if a value is a PrerenderHandlerDefinition.
*/
export declare function isPrerenderHandler(value: unknown): value is PrerenderHandlerDefinition;
//# sourceMappingURL=prerender.d.ts.map