Skip to content
App
Markdown

Deploy React Router

Deploy a React Router (framework mode, formerly Remix) app on Pilvia App — server rendering, loaders and actions in an EU-hosted isolate, client assets from the host.

React Router's framework mode, the successor of Remix, runs on Pilvia App without an adapter. Its server build is already a function from Request to Response, so you wrap it in the platform's fetch handler and let Vite bundle it. Loaders and actions run in an isolate next to your data. Prerendered pages and the client bundle are served by the host.

This page was tested with React Router 8.5, React 19.3 and Vite 8 on 2026-11-20.

The recipe

Start from any framework-mode project (bunx create-react-router@latest) and keep @react-router/node and @react-router/serve out of your dependencies. With either installed, React Router picks its Node.js server entry, which cannot run in the isolate. Without them it uses its web entry, which streams through renderToReadableStream.

Four files change.

vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [reactRouter()],
  environments: {
    ssr: {
      // One self-contained server bundle for the isolate.
      build: { rolldownOptions: { input: "./server.ts" } },
      resolve: { noExternal: true, conditions: ["edge-light"], externalConditions: ["edge-light"] },
      define: { "process.env.NODE_ENV": JSON.stringify("production") },
    },
  },
});
server.ts
import { createRequestHandler, RouterContextProvider } from "react-router";
import * as build from "virtual:react-router/server-build";
import { envContext } from "./app/env";

// React Router's own build tools (prerendering) read the server build here.
export * from "virtual:react-router/server-build";

const handler = createRequestHandler(build);

export default {
  fetch(request: Request, env: unknown) {
    return handler(request, new RouterContextProvider(new Map([[envContext, env]])));
  },
};
app/env.ts
import { createContext } from "react-router";

// The platform's env (env.kv, env.user, …), for loaders and actions.
export const envContext = createContext<any>();
pilvia.app.json
{
  "name": "my-app",
  "auth": "public",
  "kv": true,
  "bundle": "build/server/index.js",
  "assets": "build/client"
}
bunx react-router build
pilvia app deploy

Why each line is there

  • input: "./server.ts" makes your fetch handler part of React Router's own server build, so there is one copy of React Router and one of your app modules. A handler bundled separately would carry a second copy, and context.get(envContext) would fail with "No value found for context".
  • noExternal: true bundles every dependency. There is no node_modules at runtime.
  • conditions: ["edge-light"] resolves react-dom/server to React's edge renderer. Its browser renderer needs MessageChannel, which the isolate does not have. Do not add worker to the list: react-dom's package exports name worker before edge-light, so it would pick the browser renderer again.
  • define builds production React. pilvia 0.2.10 and later re-bundle in production mode anyway; with 0.2.9 and earlier, leaving it out ships React's development branch.
  • export * keeps prerendering working. React Router's build loads the server build from this module to render your prerender paths.
  • bundle and assets deploy the server module and the client output. The host serves build/client first: prerendered pages, the client bundle under assets/ with a year of immutable caching. Every other request reaches React Router, which answers its own 404s.

The platform in loaders and actions

Read the platform's env from the context in any loader, action or middleware: env.kv and env.cache, env.user and the data bindings, whatever the manifest grants.

app/routes/guestbook.tsx
import { Form, redirect } from "react-router";
import { envContext } from "../env";
import type { Route } from "./+types/guestbook";

export async function loader({ context }: Route.LoaderArgs) {
  const env = context.get(envContext);
  return { entries: (await env.kv.get("guestbook", "json")) ?? [] };
}

export async function action({ request, context }: Route.ActionArgs) {
  const env = context.get(envContext);
  const name = String((await request.formData()).get("name") ?? "").trim();
  if (!name) return { error: "name required" };
  const entries = (await env.kv.get("guestbook", "json")) ?? [];
  await env.kv.put("guestbook", [{ name, at: new Date().toISOString() }, ...entries].slice(0, 20));
  return redirect("/guestbook");
}

export default function Guestbook({ loaderData, actionData }: Route.ComponentProps) {
  return (
    <main>
      <Form method="post">
        <input name="name" />
        <button>Sign</button>
      </Form>
      {actionData?.error && <p role="alert">{actionData.error}</p>}
      <ul>{loaderData.entries.map((e: any) => <li key={e.at}>{e.name}</li>)}</ul>
    </main>
  );
}

The request headers the platform sets reach your loaders unchanged: the request id is request.headers.get("x-pilvia-request-id"), and the visitor's country is x-pilvia-ip-country.

What was tested

Against the platform's runtime and engine, with a browser for the client side:

Feature Result
Server rendering, a loader formatting a date with Intl in fi-FI ✓
Dynamic route /posts/:slug; throw data(null, { status: 404 }) ✓ 200 / 404
Unknown path through a splat route ✓ 404
Resource route returning JSON ✓
<Form method="post"> without JavaScript, action writing env.kv ✓ 302, then the new row
The same form after hydration (single fetch .data), loader revalidation ✓ 202, list updated
Cross-origin POST ✓ refused, 400
Hydration and client state ✓
A prerender page ✓ served by the host, no isolate
Client bundle under assets/ ✓ max-age=31536000, immutable

Not tested yet: sessions (createCookieSessionStorage), <Await> streaming of deferred data, and React Server Components mode.

Type to search. ↑↓ to move, Enter to open, Esc to close.