All jobs

Add Prerendering to a React Router App

Yes. An agent turns on prerender in react-router.config.ts, keeps SSR for other paths, shows the build's HTML and .data files being served, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the app's shape before it touches the config, because prerendering is decided per path. In a React Router app shaped like the default template of remix-run/react-router-templates, package.json runs react-router build, react-router dev, react-router-serve ./build/server/index.js and a typecheck script of react-router typegen && tsc; the dependencies are react-router, @react-router/node and @react-router/serve at *, react ^19.2.8, isbot ^5.1.36, with @react-router/dev, vite ^8.0.3, typescript ^5.9.3 and @tailwindcss/vite ^4.2.2 for development. react-router.config.ts sets only ssr: true, app/routes.ts registers one route, index("routes/home.tsx"), and app/routes/home.tsx exports a meta with the title New React Router App and renders Welcome from app/welcome/welcome.tsx. app/root.tsx holds the Layout with Meta, Links, ScrollRestoration and Scripts, the Google Fonts links, and the ErrorBoundary. The Dockerfile builds on node:24-alpine with npm ci and npm run build, and .gitignore excludes /build/ and /.react-router/.

With one static route and no loader, the simplest form fits: prerender: true next to ssr: true in react-router.config.ts. React Router's documentation says the boolean prerenders every static path from routes.ts and leaves dynamic segments such as /blog/:slug out because their values are unknown; the array form or the async prerender({ getStaticPaths }) function covers those. The agent keeps ssr: true, so paths that are not prerendered are still server-rendered at runtime, and it leaves app/routes.ts alone rather than inventing routes to make the list longer. It writes a short comment above the option naming the array form, with getStaticPaths() for the static part, so the next person who adds /blog/:slug knows where the values go.

The proof is the build. react-router build prints a Prerender: Generated ... line per file and writes them under build/client: an HTML file for the document request and a .data file for client-side navigations. @react-router/serve mounts express.static on the client build directory ahead of the request handler, so a request for / is answered by the prerendered file and never reaches server rendering; the agent starts npm run start in the sandbox, fetches / and compares the body with the generated HTML to show that. npm run typecheck runs because the config file is typed with satisfies Config. The agent also confirms the Dockerfile needs no change: npm run build inside the image produces the same files, and npm run start serves them.

The template repository's own CI, .github/workflows/ci.yml, runs Playwright tests from .tests/test.default.ts that typecheck, start the dev server, and build and start the app, then wait for the title and the React Router Docs link. The agent runs that suite from the repository root so the pull request shows the prerendered app passing the same build + start check the template already has, and notes that in development the documentation says nothing is written to disk, so npm run dev behaves as before.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add prerendering to this React Router app and open a pull request. Read package.json, react-router.config.ts, vite.config.ts, app/routes.ts, app/root.tsx, app/routes/home.tsx, the Dockerfile and .gitignore first. Set prerender in react-router.config.ts, keep ssr true so paths that are not prerendered still render on the server, and do not add routes; use the boolean form for the static routes that exist and leave a comment showing the array or getStaticPaths form for dynamic paths. Run npm run build and quote the Prerender lines it prints, list the HTML and .data files under build/client, start the server with npm run start, fetch / and show that the body matches the generated HTML, and run npm run typecheck. If the repository has a Playwright or other end-to-end suite, run it too. Do not change the Dockerfile unless the build inside the image needs it, and explain in the pull request what changes for a route with a loader or a dynamic segment.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that changes react-router.config.ts and nothing else in the app: the prerender option beside ssr: true and a comment with the array and getStaticPaths forms for later. The description quotes the Prerender: Generated build/client/... lines from the build, lists the HTML and .data files it wrote, and shows the response for / from react-router-serve matching the generated file, with the typecheck output and, where the repository has one, the end-to-end run.

Nothing about the Docker image changes, because npm run build inside it writes the same files and npm run start serves them. .gitignore already excludes /build/, so no generated HTML lands in the repository.

A reviewer checks that ssr stayed true, that the prerendered paths are the ones that have no per-request data, and that routes with a loader are either prerendered with data that is fine to freeze at build time or left to the server, which the pull request explains. Then they merge and rebuild.

Run it on every static page added

A team that keeps its marketing and docs pages in the same React Router app as the product sends one POST /o/{org}/sessions per repository with this prompt and the repository in resources. Each run reads its own routes.ts, so an app with /pricing and /about gets those in the list and an app with /blog/:slug gets the function form with the slugs read at build time, and each run opens its own pull request.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with session_url to read the pull request and the quoted build output from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Prerendering is one config line, and whether it did anything is only visible in the build output and in what the server answers. In a Rush sandbox the agent runs react-router build, keeps the Prerender: lines, starts react-router-serve and fetches the page, so the pull request shows the file that was written and the response that served it, with every command in the run's record.

The judgement is in what not to prerender: a route whose loader reads the signed-in user must not be frozen at build time. The agent reads each route before choosing a form, says which routes stay on the server and why, and the same request works unchanged on the next app.

Frequently asked questions

Does this turn off server rendering?

No. ssr stays true, so the documentation's rule applies: paths that are prerendered are served from the files the build wrote, and every other path is server-rendered at request time. Setting ssr: false with prerender is the static-host mode, which this change does not use.

What about routes with a loader?

React Router runs the same loader at build time by creating a Request and passing it through the app, so a prerendered route with a loader freezes that data in its .data file. The pull request names such routes and leaves any whose data depends on the request to the server.

How are dynamic paths handled?

The boolean form skips them because their parameter values are unknown. The comment the agent leaves shows the array form and the async prerender({ getStaticPaths }) form, where the static paths come from getStaticPaths() and the dynamic ones from your own list.

Does the Docker image need to change?

Not for this template. The image already runs npm run build and starts react-router-serve, which serves build/client as static files before the request handler. The agent runs the build in the sandbox to confirm the files appear.

More React Router jobs

More jobs like this: Hand off a long task

Keep reading