| 1 | import { |
| 2 | createTemporaryReferenceSet, |
| 3 | decodeAction, |
| 4 | decodeFormState, |
| 5 | decodeReply, |
| 6 | loadServerAction, |
| 7 | renderToReadableStream, |
| 8 | } from "@vitejs/plugin-rsc/rsc"; |
| 9 | import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router"; |
| 10 | import { routes } from "../app/routes"; |
| 11 | |
| 12 | export function fetchServer(request: Request) { |
| 13 | return matchRSCServerRequest({ |
| 14 | // Provide the React Server touchpoints. |
| 15 | createTemporaryReferenceSet, |
| 16 | decodeAction, |
| 17 | decodeFormState, |
| 18 | decodeReply, |
| 19 | loadServerAction, |
| 20 | // The incoming request. |
| 21 | request, |
| 22 | // The app routes. |
| 23 | routes, |
| 24 | // Encode the match with the React Server implementation. |
| 25 | generateResponse(match, options) { |
| 26 | return new Response(renderToReadableStream(match.payload, options), { |
| 27 | status: match.statusCode, |
| 28 | headers: match.headers, |
| 29 | }); |
| 30 | }, |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | if (import.meta.hot) { |
| 35 | import.meta.hot.accept(); |
| 36 | } |