Route handler code is no longer preloaded on next start since 16.3 (first request pays module evaluation)
Link to the code that reproduces this issue
https://github.com/Lezhag/next-route-handler-preload-repro
To Reproduce
npm install && npx next build./measure.sh. It runsnext start, waits 10 s so the startup preload has finished, then times two requests toGET /api/heavy.app/api/heavy/route.tsspends 500 ms at module evaluation, standing in for a large module graph (an API router, an ORM, SDK clients).
Current vs. Expected behavior
Expected (16.2.6): experimental.preloadEntriesOnStart, on by default, evaluates the route handler's module at startup. The first request costs the same as the second.
Current (16.3.x and canary): the first request still pays the full module evaluation, however long the server has been up.
| next | first GET /api/heavy |
second |
|---|---|---|
| 16.2.6 | 9 ms | 2 ms |
| 16.3.0 | 507 ms | 2 ms |
| 16.3.6 | 508 ms | 2 ms |
| 16.4.0-canary.50 | 508 ms | 2 ms |
next build --webpack on 16.3.6 also gives 508 ms, so the cause is in the server runtime, not the bundler. Pages are not affected.
Cause, as far as I can tell. Since 16.3, AppRouteRouteModule keeps the userland module behind a LazyModule (_lazyUserland, see #95791). unstable_preloadEntries() in next-server.ts still calls loadComponents() for every app path, which requires the route's entry. But nothing calls routeModule.ensureUserland(), so the handler's own code loads on its first request. #97439 describes the same deferral when it adds the load app route module span.
Impact. Any deployment that restarts servers often starts cold on every rollout. We deploy on every merge to main. After upgrading from 16.2.6 to 16.3.4, the load balancer's p99 in hours with deploys went from about 1.9 s to about 4.7 s. Hours without a deploy were unchanged. The first tRPC call on each fresh pod took 0.7–1.9 s, against 29 ms on 16.2.6.
Workaround. In instrumentation.ts, register() reads .next/server/app-paths-manifest.json and requires each */route entry. It then awaits routeModule.ensureUserland() on each one. register() resolves before any request is served, so the first request is warm again.
Suggested fix. Call await ComponentMod.routeModule?.ensureUserland?.() for app routes inside unstable_preloadEntries().
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.5.0
Available memory (MB): 49152
Available CPU cores: 12
Binaries:
Node: 24.15.0
npm: 11.12.1
Yarn: N/A
pnpm: 11.5.2
Relevant Packages:
next: 16.3.6 // Latest available version is detected (16.3.6).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: 5.9.3
Next.js Config:
output: N/AAlso reproduced on Linux amd64 (node:24-bookworm-slim) with next start on 16.3.4.
Which area(s) are affected? (Select all that apply)
Route Handlers, Performance, Runtime
Which stage(s) are affected? (Select all that apply)
Other (Deployed), next start (local)
Additional context
The regression starts at 16.3.0: 16.2.6 is the last version without LazyModule.
Source: vercel/next.js