#15533·react-router

Prerendering watches the build output directory, making large prerenders slow

Author: xPawCreated Sep 21, 2026Updated Sep 21, 2026
Labelsbugpkg:@react-router/devfeat:prerender

Reproduction

https://github.com/ValveResourceFormat/SchemaExplorer

bash
git clone https://github.com/ValveResourceFormat/SchemaExplorer
cd SchemaExplorer && npm ci
git revert --no-commit fefd95d   # removes the workaround below
PRERENDER_ALL=1 npm run build    # ~23 min
git checkout . && PRERENDER_ALL=1 npm run build   # ~6 min

Same 32,122 prerendered pages either way; the only difference is server.watch.ignored in vite.config.ts.

Timing scales with page count, so the gap is smaller on a reduced path set. Drop PRERENDER_ALL to prerender 10 pages per game instead of all of them.

System Info

bash
System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 AMD Ryzen 7 9850X3D 8-Core Processor
    Memory: 48.26 GB / 61.65 GB
  Binaries:
    Node: 24.19.0
    npm: 11.17.0
  npmPackages:
    @react-router/dev: ^8.3.0 => 8.3.1
    @react-router/node: ^8.0.1 => 8.3.1
    react-router: ^8.0.1 => 8.3.1
    vite: ^8.2.0 => 8.2.2

Also reproduced on Linux (GitHub Actions `ubuntu-latest`).

Used Package Manager

npm

Expected Behavior

Prerendering does not watch the files it is writing, and build time scales linearly with the number of prerendered pages.

Actual Behavior

Prerendering runs against a Vite preview server, which resolves config with command "serve". The plugin's child compiler is created in configResolved with:

javascript
watch: viteConfig.command === "build" ? null : viteConfig.server.watch,

The guard only covers "build", so during prerender the watcher is enabled and inherits the user's server.watch, covering the project root. Vite's resolveChokidarOptions only excludes the top-level config.build.outDir (still the default dist), not React Router's per-environment build/client, so the prerender output stays watched. Every page that lands adds fs.watch handles plus a re-stat of its directory, so cost grows superlinearly.

A CPU profile of the real build shows lstat, FSWatcher, readdirp internals and node:path normalization at ~30% of wall time, growing with page count.

Workaround, in vite.config.ts:

javascript
server: { watch: { ignored: ["**/build/**"] } },