Type resolved cacheLife profiles, dropping runtime asserts#95428
Draft
unstubbable wants to merge 1 commit into
Draft
Type resolved cacheLife profiles, dropping runtime asserts#95428unstubbable wants to merge 1 commit into
cacheLife profiles, dropping runtime asserts#95428unstubbable wants to merge 1 commit into
Conversation
Contributor
Failing test suitesCommit: 5e1a210 | About building and testing Next.js
Expand output● middleware - development errors › when middleware throws synchronously › logs the error correctly ● middleware - development errors › when middleware contains an unhandled rejection › logs the error correctly ● middleware - development errors › when running invalid dynamic code with eval › logs the error correctly |
Contributor
Stats cancelledCommit: 5e1a210 |
85e936a to
e48fb66
Compare
Base automatically changed from
hl/fix-false-positive-nested-cache-error
to
canary
July 2, 2026 21:53
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.
e48fb66 to
5e1a210
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Runtime
"use cache"code validated the default cache-life profile on every invocation becausecacheLifeProfileswas typed as optional with partial profiles:assertDefaultCacheLifeon the generate and RDC-read paths, a per-cacheLife()presenceInvariantError, and optional chaining on reads.Config normalization already guarantees this once:
assignDefaultsAndValidatebuilds the config from{...defaultConfig, ...config}, socacheLifeis always present, and it backfills thedefaultprofile'sstale,revalidate, andexpire. This moves that guarantee into the type. A newResolvedCacheLifeProfiles(inconfig-shared) types thedefaultprofile asRequired<CacheLife>and overridesNextConfigComplete.cacheLife, and the type is threaded, non-optional, through the render options, work store, and the build, export, and dev workers. Runtime code now readscacheLifeProfiles.defaultdirectly, 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 readscacheLife. It is given a sentinel whosedefaultgetter throws if ever read, matching the "never read" sentinels already used for its other unused render options.