mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #924] [MERGED] fix(cache): scope use cache entries by build id #951
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#951
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/924
Author: @NathanDrake2406
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @james-elicx
Base:
main← Head:nathan/use-cache-build-id📝 Commits (2)
de3e29cfix(cache): scope use cache entries by build id548d494fix(cache): capture use cache build id at registration📊 Changes
2 files changed (+59 additions, -5 deletions)
View changed files
📝
packages/vinext/src/shims/cache-runtime.ts(+22 -5)📝
tests/shims.test.ts(+37 -0)📄 Description
What this changes
Shared
"use cache"entries now include the vinext build ID in their persistent cache key before the cached function ID and serialized arguments. Environments without a build ID keep the previous key shape.Why
Persistent handlers such as Workers KV can outlive a deploy. Before this change, vinext keyed shared
"use cache"entries as function ID plus arguments, so a new deployment could read a serialized RSC result produced by an older function body when the generated ID and arguments stayed stable.Next.js includes
buildIdas the first part of the"use cache"key material:CacheKeyPartstuple includesbuildIdbuildIdbuildIdas the first serialized key elementApproach
registerCachedFunction()now readsprocess.env.__VINEXT_BUILD_IDand uses it to scope shared cache entries as build-specific keys. The read keeps a directprocess.env.__VINEXT_BUILD_IDreference so Vite can inline the value for Worker bundles, and it only recovers the missingprocessglobal case.The key builder encodes custom build IDs before placing them in the colon-delimited key, which avoids delimiter collisions without changing key shape when no build ID exists.
Validation
git diff --checkvp test run tests/shims.test.ts -t 'scopes shared cache entries by build ID'vp test run tests/shims.test.ts -t '"use cache" runtime'vp check packages/vinext/src/shims/cache-runtime.ts tests/shims.test.tsvp test run tests/shims.test.tsvp run vinext#buildRisks / follow-ups
This intentionally invalidates existing shared
"use cache"entries on the next deploy when a build ID is available. That is the desired Next.js-compatible behavior for code-derived cached RSC streams.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.