fix(shims): add unstable_cacheLife and unstable_cacheTag to next/cache#1202
Conversation
Next.js exports unstable_cacheLife and unstable_cacheTag as deprecation aliases that emit a one-time console.error and delegate to the stabilized cacheLife / cacheTag. Several Next.js apps in the deploy suite still import the unstable_ names, so vinext apps fail to build with [MISSING_EXPORT] errors. Match Next.js's behavior exactly: same warning text, same one-time-per-process gating, same delegation.
|
/bigbonk review |
commit: |
|
There was a problem hiding this comment.
LGTM. Clean, well-scoped change that matches the established unstable_io deprecation alias pattern already in this file.
What I checked:
-
Implementation mirrors the exact Next.js
packages/next/cache.jspattern: module-leveldidWarnflag,console.error(new Error(...))(not a bare string), then delegation to the stabilized function. TheErrorwrapping is important because the Next.js test asserts"Error: \unstable_cacheLife`..."in CLI output, which comes fromconsole.error(new Error(...))`. -
Signatures match:
unstable_cacheLife(profile: string | CacheLifeConfig)matchescacheLife, andunstable_cacheTag(...tags: string[])matchescacheTag. Both returnvoid(matching the delegation targets). -
Tests follow the same shape as the existing
unstable_iotest at line 2336 — spy on console, call the function, assert the warning fires. Theinstanceof Errorcheck in thewarnedassertion is correct since the implementation passesnew Error(...). -
The test-ordering sensitivity from module-level
_unstableCacheLifeWarned/_unstableCacheTagWarnedflags is the same as_unstableIoWarned— the warned flag can only fire once per module load. Since the tests only assert the warning was seen (.some(...)) and don't assert it fires on the second call, this is fine. If these tests run after some other test that already triggered the alias, the flag would betrueand no warning would fire. But since the module is dynamically imported and Vitest's module cache is per-file, this isn't a practical problem here. -
JSDoc links back to the Next.js source and the asserting test file. Placement in the file is correct (between
cacheTagand theunstable_cachesection). -
Check passed, and the change is purely additive (no behavioral changes to existing exports).
|
Approved PR #1202. The change is clean and well-scoped:
|
Summary
Adds
unstable_cacheLifeandunstable_cacheTagexports topackages/vinext/src/shims/cache.tsas deprecation-warning aliases that delegate to the stabilizedcacheLifeandcacheTag.This unblocks 6 build failures in the Next.js deploy suite where apps import the
unstable_-prefixed names and Rolldown rejects the build with:Behavior: deprecation-warning aliases (not hard aliases)
Next.js wraps each call in a one-time
console.error(new Error(...))and then delegates to the stabilized counterpart. We mirror that exactly.Evidence — Next.js source (
packages/next/cache.js):(Same shape for
unstable_cacheTag.)Next.js test asserts CLI output literally contains the warning text:
test/e2e/app-dir/cache-components-errors/cache-components-unstable-deprecations.test.tsfixtures/unstable-deprecations/app/{life,tag}/page.tsximportunstable_cacheLife/unstable_cacheTagfromnext/cacheand expect:expect(next.cliOutput).toContain('Error: \unstable_cacheLife` was recently stabilized')`expect(next.cliOutput).toContain('Error: \unstable_cacheTag` was recently stabilized')`The
"Error: "prefix in the assertion comes from passing anErrorinstance toconsole.error— so we passnew Error(...)rather than a bare string to keep the exact surface behavior.Implementation
packages/vinext/src/shims/cache.ts:unstable_cacheLife(profile: string | CacheLifeConfig)— emits the deprecation warning once, then delegates tocacheLife(profile). Signature matchescacheLife.unstable_cacheTag(...tags: string[])— emits the deprecation warning once, then delegates tocacheTag(...tags). Signature matchescacheTag._unstable*Warnedflag (mirrors Next.js'sdidWarnCacheLife/didWarnCacheTag).tests/shims.test.ts:unstable_cacheLife is exported as a deprecation alias for cacheLife— asserts the export is a function, both(profile: string)and(profile: object)forms work without throwing, andconsole.erroris called with a message containing`unstable_cacheLife` was recently stabilized.unstable_cacheTag is exported as a deprecation alias for cacheTag— asserts the export is a function, variadic tag form works without throwing, andconsole.erroris called with the matching warning text.unstable_iodeprecation-alias test in this file.Checks
vp test run tests/shims.test.ts— both new tests pass (plus all sibling cache shim tests).vp check— clean (1241 files formatted, 548 files lint/type-clean).packages/vinext/src/shims/cache.tsandtests/shims.test.tsper the task constraints.Test Plan