next.js
f83bc252 - Type resolved `cacheLife` profiles, dropping runtime asserts (#95428)

Commit
41 days ago
Type resolved `cacheLife` profiles, dropping runtime asserts (#95428) Runtime `"use cache"` code validated the default cache-life profile on every invocation because `cacheLifeProfiles` was typed as optional with partial profiles: `assertDefaultCacheLife` on the generate and RDC-read paths, a per-`cacheLife()` presence `InvariantError`, and optional chaining on reads. Config normalization already guarantees this once: `assignDefaultsAndValidate` builds the config from `{...defaultConfig, ...config}`, so `cacheLife` is always present, and it backfills the `default` profile's `stale`, `revalidate`, and `expire`. This moves that guarantee into the type. A new `ResolvedCacheLifeProfiles` (in `config-shared`) types the `default` profile as `Required<CacheLife>` and overrides `NextConfigComplete.cacheLife`, and the type is threaded, non-optional, through the render options, work store, and the build, export, and dev workers. Runtime code now reads `cacheLifeProfiles.default` directly, and the asserts, the presence guard, and the optional chaining are gone. The proxy (middleware) work store is the one construction site without a resolved profile: the proxy does not support `"use cache"`, so it never reads `cacheLife`. It is given a sentinel whose `default` getter throws if ever read, matching the "never read" sentinels already used for its other unused render options.
Author
Parents
Loading