This template runs React Router's experimental RSC Framework Mode on Cloudflare Workers.
Warning: RSC Framework Mode is experimental.
pnpm install
pnpm devStarting from the RSC Framework Mode template:
pnpm add -D @cloudflare/vite-plugin wrangler
pnpm remove @react-router/serve @remix-run/node-fetch-serverimport { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({
plugins: [
cloudflare({
viteEnvironment: {
name: "rsc",
childEnvironments: ["ssr"],
},
}),
// ... keep existing plugins, but update rsc():
rsc({ serverHandler: false }),
],
environments: {
rsc: {
optimizeDeps: {
exclude: ["react-router"],
},
},
ssr: {
optimizeDeps: {
exclude: ["react-router"],
},
},
},
});Note: See Known Issues for why
serverHandler: falseandoptimizeDeps.excludeare needed.
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "my-app",
"main": "@react-router/dev/config/default-rsc-entries/entry.rsc",
"compatibility_date": "2026-01-29",
"compatibility_flags": ["nodejs_compat"]
}mainpoints to React Router's default RSC entry (no custom worker needed)nodejs_compatis required for React's usage on Async Local Storage APIs
The rest follows the standard Cloudflare React Router setup:
- package.json - Add
preview,deploy,cf-typegenscripts - tsconfig.json, tsconfig.node.json, tsconfig.cloudflare.json
- .gitignore - Add
/.wrangler/
These workarounds will be resolved in future versions of the plugins.
Invalid hook call errors after clearing node_modules/.vite. The reactRouterRSC plugin's optimizeDeps.include for react-router can cause duplicate React instances in worker environments.
Fix: Exclude react-router from optimization in rsc/ssr environments (see config above).
ERR_UNSUPPORTED_ESM_URL_SCHEME when using Durable Objects or other cloudflare:* imports. The @vitejs/plugin-rsc preview server tries to import the RSC entry in Node.js, which doesn't support cloudflare:*.
Fix: Set rsc({ serverHandler: false }) since the Cloudflare plugin handles requests via workerd.