next.js
cdc390ba - Serve cached misses from the filesystem route cache (#96230)

Commit
99 days ago
Serve cached misses from the filesystem route cache (#96230) `getItem` stores `null` for paths that don't resolve, but checks the cached value with `if (lruResult)`, so a cached `null` is never served: every request for an unknown path — including every dynamic-route request — re-runs the lookup. It's been this way since the cache was introduced in #52492. Return the cached entry whenever the key is present. This can't go stale: in production the item sets are only populated during `setupFsCheck`, and the LRU is disabled in dev. Cached misses are stored as a dedicated sentinel instead of `null`. Since serving a cached miss has no observable effect, no test can catch this regressing — that is also why it went unnoticed. With the sentinel it's a type error instead: reintroducing the truthy check fails `pnpm types` (verified). Same pattern as `invalidSourceMap` in `source-maps.ts`. Stacked on #96229, which bounds what negative entries can retain. ## Test Plan No direct test: the change is unobservable by design, and the existing e2e suites assert that it stays that way. The regression guard is the type system, as above. `test/e2e/app-dir/not-found/basic` passes in prod mode (14/14), exercising the negative-cache path.
Author
Parents
Loading