mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #99] [MERGED] fix: use AsyncLocalStorage.run() for request context isolation #309
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#309
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/99
Author: @southpolesteve
Created: 2/26/2026
Status: ✅ Merged
Merged: 2/26/2026
Merged by: @southpolesteve
Base:
main← Head:fix/als-run-wrapping📝 Commits (1)
cc6389efix: use AsyncLocalStorage.run() for request context isolation📊 Changes
10 files changed (+191 additions, -193 deletions)
View changed files
📝
packages/vinext/src/index.ts(+15 -4)📝
packages/vinext/src/server/app-dev-server.ts(+38 -30)📝
packages/vinext/src/server/dev-server.ts(+19 -12)📝
packages/vinext/src/shims/cache-runtime.ts(+19 -15)📝
packages/vinext/src/shims/cache.ts(+20 -15)📝
packages/vinext/src/shims/fetch-cache.ts(+2 -3)📝
packages/vinext/src/shims/head-state.ts(+18 -15)📝
packages/vinext/src/shims/headers.ts(+25 -49)📝
packages/vinext/src/shims/navigation-state.ts(+19 -29)📝
packages/vinext/src/shims/router-state.ts(+16 -21)📄 Description
Summary
Replaces
enterWith()withrun()across all AsyncLocalStorage-backed state modules to ensure per-request state is properly scoped.enterWith()is not supported on all runtimes (notably Cloudflare Workers), and the fallback pattern was not concurrency-safe.What changed:
headers.ts,navigation-state.ts,router-state.ts,head-state.ts,cache.ts,cache-runtime.ts) now use_als.run(state, fn)instead of_enterWith()+ fallback globalsrunWith*()function that creates a scoped ALS contextwithFetchCache()init/cleanup pattern is removed; onlyrunWithFetchCache()remainsrunWith*()chainrunWithNavigationContextscope since it runs in a separate Vite environment with separate module instances🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.