mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #279] [MERGED] fix: throw when dynamic request APIs are called inside cache scopes #438
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#438
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/279
Author: @southpolesteve
Created: 3/6/2026
Status: ✅ Merged
Merged: 3/6/2026
Merged by: @southpolesteve
Base:
main← Head:fix/cache-scope-dynamic-api-guards📝 Commits (2)
bce3620fix: throw when headers()/cookies()/connection() called inside cache scopeb5d1920fix: add draftMode() cache scope guard, remove dead code, add nested scope test📊 Changes
5 files changed (+373 additions, -4 deletions)
View changed files
📝
packages/vinext/src/shims/cache-runtime.ts(+7 -1)📝
packages/vinext/src/shims/cache.ts(+23 -2)📝
packages/vinext/src/shims/headers.ts(+53 -0)📝
packages/vinext/src/shims/server.ts(+2 -1)📝
tests/shims.test.ts(+288 -0)📄 Description
Summary
headers(),cookies(), orconnection()are called inside"use cache"functions orunstable_cache()callbacks, matching Next.js behaviorunstable_cache()callback is now wrapped in an AsyncLocalStorage scope so the guard can detect it"use cache"runtime'scacheContextStorageALS is stored onglobalThisvia a well-known Symbol soheaders.tscan read it without introducing circular importsChanges
shims/headers.tsthrowIfInsideCacheScope()guard called byheaders()andcookies(). Reads cache scope ALS instances from globalThis via Symbols to avoid circular imports.shims/server.tsconnection()now callsthrowIfInsideCacheScope()beforemarkDynamicUsage()shims/cache.tsunstable_cache()wraps its callback in an ALS scope (_unstableCacheAls) stored on globalThisshims/cache-runtime.tscacheContextStoragenow stored on globalThis via Symbol (was a bare module-level variable). AddedisInsideCacheScope()export.tests/shims.test.tsTesting
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.