| 1 |
|
| 2 | import { Location } from "../router/history.js";
|
| 3 | import { ActionFunction, LoaderFunction, Params, RouterContextProvider, ShouldRevalidateFunction } from "../router/utils.js";
|
| 4 | import { ClientActionFunction, ClientLoaderFunction, HeadersFunction, LinksFunction, MetaFunction } from "../dom/ssr/routeModules.js";
|
| 5 | import * as React$1 from "react";
|
| 6 | import { ReactFormState } from "react-dom/client";
|
| 7 |
|
| 8 |
|
| 9 | declare function getRequest(): Request;
|
| 10 | type RSCRouteConfigEntryBase = {
|
| 11 | action?: ActionFunction;
|
| 12 | clientAction?: ClientActionFunction;
|
| 13 | clientLoader?: ClientLoaderFunction;
|
| 14 | ErrorBoundary?: React$1.ComponentType<any>;
|
| 15 | handle?: any;
|
| 16 | headers?: HeadersFunction;
|
| 17 | HydrateFallback?: React$1.ComponentType<any>;
|
| 18 | Layout?: React$1.ComponentType<any>;
|
| 19 | links?: LinksFunction;
|
| 20 | loader?: LoaderFunction;
|
| 21 | meta?: MetaFunction;
|
| 22 | shouldRevalidate?: ShouldRevalidateFunction;
|
| 23 | };
|
| 24 | type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
|
| 25 | id: string;
|
| 26 | path?: string;
|
| 27 | Component?: React$1.ComponentType<any>;
|
| 28 | lazy?: () => Promise<RSCRouteConfigEntryBase & ({
|
| 29 | default?: React$1.ComponentType<any>;
|
| 30 | Component?: never;
|
| 31 | } | {
|
| 32 | default?: never;
|
| 33 | Component?: React$1.ComponentType<any>;
|
| 34 | })>;
|
| 35 | } & ({
|
| 36 | index: true;
|
| 37 | } | {
|
| 38 | children?: RSCRouteConfigEntry[];
|
| 39 | });
|
| 40 | type RSCRouteConfig = Array<RSCRouteConfigEntry>;
|
| 41 | type RSCRouteManifest = {
|
| 42 | clientAction?: ClientActionFunction;
|
| 43 | clientLoader?: ClientLoaderFunction;
|
| 44 | element?: React$1.ReactElement | false;
|
| 45 | errorElement?: React$1.ReactElement;
|
| 46 | handle?: any;
|
| 47 | hasAction: boolean;
|
| 48 | hasComponent: boolean;
|
| 49 | hasLoader: boolean;
|
| 50 | hydrateFallbackElement?: React$1.ReactElement;
|
| 51 | id: string;
|
| 52 | index?: boolean;
|
| 53 | links?: LinksFunction;
|
| 54 | meta?: MetaFunction;
|
| 55 | parentId?: string;
|
| 56 | path?: string;
|
| 57 | shouldRevalidate?: ShouldRevalidateFunction;
|
| 58 | };
|
| 59 | type RSCRouteMatch = RSCRouteManifest & {
|
| 60 | params: Params;
|
| 61 | pathname: string;
|
| 62 | pathnameBase: string;
|
| 63 | };
|
| 64 | type RSCRenderPayload = {
|
| 65 | type: "render";
|
| 66 | actionData: Record<string, any> | null;
|
| 67 | basename: string | undefined;
|
| 68 | clientVersion?: string;
|
| 69 | errors: Record<string, any> | null;
|
| 70 | loaderData: Record<string, any>;
|
| 71 | location: Location;
|
| 72 | routeDiscovery: RouteDiscovery;
|
| 73 | matches: RSCRouteMatch[];
|
| 74 | patches?: Promise<RSCRouteManifest[]>;
|
| 75 | formState?: ReactFormState;
|
| 76 | };
|
| 77 | type RSCManifestPayload = {
|
| 78 | type: "manifest";
|
| 79 | patches: Promise<RSCRouteManifest[]>;
|
| 80 | };
|
| 81 | type RSCActionPayload = {
|
| 82 | type: "action";
|
| 83 | actionResult: Promise<unknown>;
|
| 84 | rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
|
| 85 | };
|
| 86 | type RSCRedirectPayload = {
|
| 87 | type: "redirect";
|
| 88 | status: number;
|
| 89 | location: string;
|
| 90 | replace: boolean;
|
| 91 | reload: boolean;
|
| 92 | actionResult?: Promise<unknown>;
|
| 93 | };
|
| 94 | type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
|
| 95 | type RSCMatch = {
|
| 96 | statusCode: number;
|
| 97 | headers: Headers;
|
| 98 | payload: RSCPayload;
|
| 99 | };
|
| 100 | type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
|
| 101 | type DecodeFormStateFunction = (result: unknown, formData: FormData) => Promise<ReactFormState | undefined>;
|
| 102 | type DecodeReplyFunction = (reply: FormData | string, options: {
|
| 103 | temporaryReferences: unknown;
|
| 104 | }) => Promise<unknown[]>;
|
| 105 | type LoadServerActionFunction = (id: string) => Promise<Function>;
|
| 106 | type RouteDiscovery = {
|
| 107 | mode: "lazy";
|
| 108 | manifestPath?: string | undefined;
|
| 109 | } | {
|
| 110 | mode: "initial";
|
| 111 | };
|
| 112 | |
| 113 | * Matches the given routes to a [`Request`](https:
|
| 114 | * and returns an [RSC](https:
|
| 115 | * [`Response`](https:
|
| 116 | * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https:
|
| 117 | * enabled client router.
|
| 118 | *
|
| 119 | * @example
|
| 120 | * import {
|
| 121 | * createTemporaryReferenceSet,
|
| 122 | * decodeAction,
|
| 123 | * decodeReply,
|
| 124 | * loadServerAction,
|
| 125 | * renderToReadableStream,
|
| 126 | * } from "@vitejs/plugin-rsc/rsc";
|
| 127 | * import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
|
| 128 | *
|
| 129 | * matchRSCServerRequest({
|
| 130 | * createTemporaryReferenceSet,
|
| 131 | * decodeAction,
|
| 132 | * decodeFormState,
|
| 133 | * decodeReply,
|
| 134 | * loadServerAction,
|
| 135 | * request,
|
| 136 | * routes: routes(),
|
| 137 | * generateResponse(match) {
|
| 138 | * return new Response(
|
| 139 | * renderToReadableStream(match.payload),
|
| 140 | * {
|
| 141 | * status: match.statusCode,
|
| 142 | * headers: match.headers,
|
| 143 | * }
|
| 144 | * );
|
| 145 | * },
|
| 146 | * });
|
| 147 | *
|
| 148 | * @name unstable_matchRSCServerRequest
|
| 149 | * @public
|
| 150 | * @category RSC
|
| 151 | * @mode data
|
| 152 | * @param opts Options
|
| 153 | * @param opts.allowedActionOrigins Origin patterns that are allowed to execute actions.
|
| 154 | * @param opts.basename The basename to use when matching the request.
|
| 155 | * @param opts.createTemporaryReferenceSet A function that returns a temporary
|
| 156 | * reference set for the request, used to track temporary references in the [RSC](https:
|
| 157 | * stream.
|
| 158 | * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
|
| 159 | * function, responsible for loading a server action.
|
| 160 | * @param opts.decodeFormState A function responsible for decoding form state for
|
| 161 | * progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
|
| 162 | * using your `react-server-dom-xyz/server`'s `decodeFormState`.
|
| 163 | * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
|
| 164 | * function, used to decode the server function's arguments and bind them to the
|
| 165 | * implementation for invocation by the router.
|
| 166 | * @param opts.generateResponse A function responsible for using your
|
| 167 | * `renderToReadableStream` to generate a [`Response`](https:
|
| 168 | * encoding the {@link unstable_RSCPayload}.
|
| 169 | * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
|
| 170 | * `loadServerAction` function, used to load a server action by ID.
|
| 171 | * @param opts.clientVersion A version derived from the client build output used
|
| 172 | * to detect stale clients during lazy route discovery.
|
| 173 | * @param opts.onError An optional error handler that will be called with any
|
| 174 | * errors that occur during the request processing.
|
| 175 | * @param opts.request The [`Request`](https:
|
| 176 | * to match against.
|
| 177 | * @param opts.requestContext An instance of {@link RouterContextProvider}
|
| 178 | * that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
|
| 179 | * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
|
| 180 | * @param opts.routeDiscovery The route discovery configuration, used to determine how the router should discover new routes during navigations.
|
| 181 | * @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
|
| 182 | * @returns A [`Response`](https:
|
| 183 | * that contains the [RSC](https:
|
| 184 | * data for hydration.
|
| 185 | */
|
| 186 | declare function matchRSCServerRequest({
|
| 187 | allowedActionOrigins,
|
| 188 | createTemporaryReferenceSet,
|
| 189 | basename,
|
| 190 | decodeReply,
|
| 191 | requestContext,
|
| 192 | routeDiscovery,
|
| 193 | loadServerAction,
|
| 194 | decodeAction,
|
| 195 | decodeFormState,
|
| 196 | clientVersion,
|
| 197 | onError,
|
| 198 | request,
|
| 199 | routes,
|
| 200 | generateResponse
|
| 201 | }: {
|
| 202 | allowedActionOrigins?: string[];
|
| 203 | createTemporaryReferenceSet: () => unknown;
|
| 204 | basename?: string;
|
| 205 | decodeReply?: DecodeReplyFunction;
|
| 206 | decodeAction?: DecodeActionFunction;
|
| 207 | decodeFormState?: DecodeFormStateFunction;
|
| 208 | requestContext?: RouterContextProvider;
|
| 209 | loadServerAction?: LoadServerActionFunction;
|
| 210 | clientVersion?: string;
|
| 211 | onError?: (error: unknown) => void;
|
| 212 | request: Request;
|
| 213 | routes: RSCRouteConfigEntry[];
|
| 214 | routeDiscovery?: RouteDiscovery;
|
| 215 | generateResponse: (match: RSCMatch, {
|
| 216 | onError,
|
| 217 | temporaryReferences
|
| 218 | }: {
|
| 219 | onError(error: unknown): string | undefined;
|
| 220 | temporaryReferences: unknown;
|
| 221 | }) => Response;
|
| 222 | }): Promise<Response>;
|
| 223 |
|
| 224 | export { DecodeActionFunction, DecodeFormStateFunction, DecodeReplyFunction, LoadServerActionFunction, RSCManifestPayload, RSCMatch, RSCPayload, RSCRenderPayload, RSCRouteConfig, RSCRouteConfigEntry, RSCRouteManifest, RSCRouteMatch, getRequest, matchRSCServerRequest }; |
| \ | No newline at end of file |