UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

36 lines (35 loc) 1.6 kB
import type { CallServerCallback } from "react-server-dom-webpack/client.browser"; export type { HydrationOptions } from "react-dom/client"; export type { CallServerCallback } from "react-server-dom-webpack/client.browser"; export type RscActionResponse<Result> = { node: React.ReactNode; actionResult: Result; }; export type ActionResponseData = { status: number; headers: { location: string | null; }; }; export type ActionResponseMeta = { __rw_action_response: ActionResponseData; }; export declare function isActionResponse(value: unknown): value is ActionResponseMeta; export type TransportContext = { setRscPayload: <Result>(v: Promise<RscActionResponse<Result>>) => void; handleResponse?: (response: Response) => boolean; /** * Optional callback invoked after a new RSC payload has been committed on the client. * This is useful for features like client-side navigation that want to run logic * after hydration/updates, e.g. warming navigation caches. */ onHydrationUpdate?: () => void; /** * Optional callback invoked when an action returns a Response. * Return true to signal that the response has been handled and * default behaviour (e.g. redirects) should be skipped. */ onActionResponse?: (actionResponse: ActionResponseData) => boolean | void; }; export type Transport = (context: TransportContext) => CallServerCallback; export type CreateCallServer = (context: TransportContext) => <Result>(id: null | string, args: null | unknown[], source?: "action" | "navigation") => Promise<Result>;