/** * @jorvel/ssr — renderToReadableStream (Web Streams / edge runtimes). * * Wraps React 18's `renderToReadableStream` so it works inside Cloudflare * Workers / Vercel Edge / Deno Deploy. Unlike `render-to-stream.ts` this file * has zero `node:*` imports, so it stays loadable in `@jorvel/ssr/edge`. * * The streaming render is exposed as either: * - a `Response` (ready-to-return from an edge handler), or * - a `ReadableStream` + metadata for callers that need to set * status / headers themselves. */ import type { ComponentType } from 'react'; import type { SsrRoute } from './types.js'; export interface RenderRouteToReadableStreamOptions { signal?: AbortSignal; /** Bootstrap modules / inline script — passed straight to React. */ bootstrapScripts?: string[]; bootstrapModules?: string[]; bootstrapScriptContent?: string; /** Identifier prefix for React-emitted ids — required if you mount more than one root. */ identifierPrefix?: string; /** Custom nonce attached to React's inline runtime scripts (CSP-friendly). */ nonce?: string; /** Suspense-boundary error reporter. */ onError?: (err: unknown) => void; /** When true, awaits `allReady` before resolving (good for crawlers / SEO). Default: false. */ waitForAllReady?: boolean; /** Hard timeout — aborts the render after this many ms. */ timeoutMs?: number; } export interface ReadableStreamRenderResult { /** Web `ReadableStream` with the rendered HTML. */ stream: ReadableStream; /** Captured Suspense-boundary errors. */ errors: Error[]; /** 200 on success, 500 if the shell failed. */ statusCode: number; /** Cooperatively abort the in-flight render. */ abort: () => void; } interface ReactReadableStream extends ReadableStream { allReady: Promise; } interface ReactDomServerWeb { renderToReadableStream: (children: unknown, options?: { signal?: AbortSignal; bootstrapScripts?: string[]; bootstrapModules?: string[]; bootstrapScriptContent?: string; identifierPrefix?: string; nonce?: string; onError?: (err: unknown) => void; }) => Promise; } /** Allow tests to inject a fake `react-dom/server.browser` without touching the cache. */ export declare function _setReactDomServerWeb(impl: ReactDomServerWeb | null): void; export declare function renderRouteToReadableStream(App: ComponentType<{ path: string; params?: Record; }>, route: SsrRoute, opts?: RenderRouteToReadableStreamOptions): Promise; export interface RenderRouteAsResponseOptions extends RenderRouteToReadableStreamOptions { headers?: HeadersInit; /** Wraps the streamed body with `` + a shell template. Default: identity. */ shell?: (body: ReadableStream) => ReadableStream; } export declare function renderRouteToResponse(App: ComponentType<{ path: string; params?: Record; }>, route: SsrRoute, opts?: RenderRouteAsResponseOptions): Promise; /** Read a Web ReadableStream into a string. Useful in tests. */ export declare function collectReadableStream(stream: ReadableStream): Promise; export {}; //# sourceMappingURL=render-to-readable-stream.d.ts.map