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

Stale Route-Cache Entries Survive In-Place Deploy Due To Build-Independent Cache Key In Next.Js 16.3.8

Next.js 16.3.8 introduced a regression where the route-cache key no longer depends on the build ID. In non-atomic in-place deployments that patch the .next directory without clearing .next/server/route-cache, stale cache entries reference old hashed assets, causing 404s for CSS and JS files after deployment.

highConfidence 87%Next.jsAffected V16.3.8Affected V16.4.0-Canary.60Affected V>=16.3.8

Origin Analysis

PR #99482 changed route-cache-key.ts to generate cache keys without including a build-specific identifier. Since the route-cache directory is written at runtime and is not part of the build output, deployments that patch .next in place leave old cache files intact. The unchanged key format causes the server to continue reading stale cached responses referencing previous build assets, leading to broken pages.
1. Deploy a Next.js app with version 16.3.7; 2. Access a page that gets cached in .next/server/route-cache; 3. Upgrade to 16.3.8 without clearing route-cache; 4. Deploy new build in non-atomic mode (e.g. DeployHQ over SSH, patching only changed files); 5. Restart `next start`; 6. Request previously cached page and observe 404 for hashed CSS/JS assets.

Fixing Code Block

Edge Case Audit

Reading and caching the build ID in memory works for a single build per process, but in multi-tenant or rolling update scenarios where multiple builds share a server, a process restart is required to pick up the new ID. If the code is deployed without clearing the old route-cache, the first request after upgrade will still hit the old key until the server restarts, so a restart (or automatic purge on boot) is recommended. Rollback is safe: revert the key change and manually delete .next/server/route-cache to avoid mixing old and new formats.

Ecosystem Topology