AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Route Handler Code No Longer Preloaded On Next Start Since 16.3

Next.js 16.3 introduced a regression where route handler modules are not eagerly evaluated at startup, causing the first request to a route handler to pay full module evaluation cost. This increases cold start latency and p99 for deployments.

highConfidence 95%Next.jsAffected V16.3.0Affected V16.3.1Affected V16.3.2Affected V16.3.3Affected V16.3.4Affected V16.3.5Affected V16.3.6Affected V16.4.0-Canary.50

Origin Analysis

Since Next.js 16.3, AppRouteRouteModule wraps userland code in LazyModule (_lazyUserland). The startup preload mechanism (unstable_preloadEntries in next-server.ts) calls loadComponents() but does not trigger routeModule.ensureUserland(), leaving module evaluation deferred until first request.
1. Create a Next.js app with an app/api/heavy/route.ts that spends 500ms at module evaluation. 2. Run next build and next start. 3. Wait for startup (10s) then time two GET /api/heavy requests. Observe first request ~500ms, second ~2ms on affected versions.

Fixing Code Block

Edge Case Audit

This fix increases startup time and memory usage as all route handlers are fully evaluated at boot, which may be undesirable for apps with many huge route modules. In concurrent or multi-threaded environments, ensure that preloading is idempotent and does not conflict with lazy loading assumptions. If rollback is needed, revert this change and rely on runtime lazy loading; consider making preloading configurable via experimental flag.

Ecosystem Topology