本页还没有译文
本页 41 段还没译成日本語,下面显示的是英文原文。matchRSCServerRequest
还没翻译译自英文(reactrouter.com)本页 41 段都还没译
unstable_matchRSCServerRequest
Data
Warning
This API is experimental and subject to breaking changes in minor/patch releases. Please use with caution and pay very close attention to release notes for relevant changes.
Summary
Matches the given routes to a Request
and returns an RSC
Response
encoding an unstable_RSCPayload for consumption by an RSC
enabled client router.
Treat every React Server Function as a public endpoint. Server Functions are not inherently associated with a route. Any route middleware that runs is selected from the URL used to call a Server Function, but the client controls both the Server Function identifier and the URL. Perform all access control checks within each Server Function, or use a route action for middleware-driven access control.
import {
createTemporaryReferenceSet,
decodeAction,
decodeReply,
loadServerAction,
renderToReadableStream,
} from "@vitejs/plugin-rsc/rsc";
import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
matchRSCServerRequest({
createTemporaryReferenceSet,
decodeAction,
decodeFormState,
decodeReply,
loadServerAction,
request,
routes: routes(),
generateResponse(match) {
return new Response(
renderToReadableStream(match.payload),
{
status: match.statusCode,
headers: match.headers,
}
);
},
});Signature
async function matchRSCServerRequest({
allowedActionOrigins,
createTemporaryReferenceSet,
basename,
decodeReply,
requestContext,
routeDiscovery,
loadServerAction,
decodeAction,
decodeFormState,
clientVersion,
onError,
request,
routes,
generateResponse: encodeResponse,
}: {
allowedActionOrigins?: string[];
createTemporaryReferenceSet: () => unknown;
basename?: string;
decodeReply?: DecodeReplyFunction;
decodeAction?: DecodeActionFunction;
decodeFormState?: DecodeFormStateFunction;
requestContext?: RouterContextProvider;
loadServerAction?: LoadServerActionFunction;
clientVersion?: string;
onError?: (error: unknown) => void;
request: Request;
routes: RSCRouteConfigEntry[];
routeDiscovery?: RouteDiscovery;
generateResponse: (
match: RSCMatch,
{
onError,
temporaryReferences,
}: {
onError(error: unknown): string | undefined;
temporaryReferences: unknown;
},
) => Response;
}): Promise<Response>Params
opts.allowedActionOrigins
Origin patterns that are allowed to execute actions.
opts.basename
The basename to use when matching the request.
opts.createTemporaryReferenceSet
A function that returns a temporary reference set for the request, used to track temporary references in the RSC stream.
opts.decodeAction
Your react-server-dom-xyz/server's decodeAction function, responsible for loading a server action.
opts.decodeFormState
A function responsible for decoding form state for progressively enhanceable forms with React's useActionState
using your react-server-dom-xyz/server's decodeFormState.
opts.decodeReply
Your react-server-dom-xyz/server's decodeReply function, used to decode the server function's arguments and bind them to the
implementation for invocation by the router.
opts.generateResponse
A function responsible for using your renderToReadableStream to generate a Response
encoding the unstable_RSCPayload.
opts.loadServerAction
Your react-server-dom-xyz/server's loadServerAction function, used to load a server action by ID.
opts.clientVersion
A version derived from the client build output used to detect stale clients during lazy route discovery.
opts.onError
An optional error handler that will be called with any errors that occur during the request processing.
opts.request
The Request to match against.
opts.requestContext
An instance of RouterContextProvider that should be created per request, to be passed to actions,
loaders and middleware.
opts.routeDiscovery
The route discovery configuration, used to determine how the router should discover new routes during navigations.
opts.routes
Your route definitions.