Matches the given routes to a Request
and returns an RSC
Response
encoding an unstable_RSCPayload
for consumption by an RSC
enabled client router.
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,
}
);
},
});
async function matchRSCServerRequest({
createTemporaryReferenceSet,
basename,
decodeReply,
requestContext,
loadServerAction,
decodeAction,
decodeFormState,
onError,
request,
routes,
generateResponse,
}: {
createTemporaryReferenceSet: () => unknown;
basename?: string;
decodeReply?: DecodeReplyFunction;
decodeAction?: DecodeActionFunction;
decodeFormState?: DecodeFormStateFunction;
requestContext?: unstable_RouterContextProvider;
loadServerAction?: LoadServerActionFunction;
onError?: (error: unknown) => void;
request: Request;
routes: RSCRouteConfigEntry[];
generateResponse: (
match: RSCMatch,
{
temporaryReferences,
}: {
temporaryReferences: unknown;
},
) => Response;
}): Promise<Response>
The basename to use when matching the request.
A function that returns a temporary reference set for the request, used to track temporary references in the RSC stream.
Your react-server-dom-xyz/server
's decodeAction
function, responsible for loading a server action.
A function responsible for decoding form state for progressively enhanceable forms with React's useActionState
using your react-server-dom-xyz/server
's decodeFormState
.
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.
A function responsible for using your renderToReadableStream
to generate a Response
encoding the unstable_RSCPayload
.
Your react-server-dom-xyz/server
's loadServerAction
function, used to load a server action by ID.
An optional error handler that will be called with any errors that occur during the request processing.
The Request
to match against.
An instance of unstable_RouterContextProvider
that should be created per request, to be passed to action
s,
loader
s and middleware.
Your route definitions.