mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #608] [CLOSED] feat: add per-request store API (getRequestStore) #707
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#707
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/608
Author: @JamesbbBriz
Created: 3/20/2026
Status: ❌ Closed
Base:
main← Head:feat/request-store📝 Commits (1)
5e3cb12feat: add per-request store API for user-defined data📊 Changes
5 files changed (+106 additions, -3 deletions)
View changed files
📝
packages/vinext/package.json(+4 -0)📝
packages/vinext/src/entries/pages-server-entry.ts(+6 -1)📝
packages/vinext/src/server/api-handler.ts(+8 -2)➕
packages/vinext/src/shims/request-store.ts(+83 -0)📝
packages/vinext/src/shims/unified-request-context.ts(+5 -0)📄 Description
Summary
Add
getRequestStore()— a per-request key-value store backed by vinext's existing unifiedAsyncLocalStoragescope. Values are isolated per request and automatically garbage-collected when the request completes.Primary use case: per-request database clients on Cloudflare Workers, where global singletons cause alternating request failures (#537).
API
Similar pattern to SvelteKit
event.locals, Honoc.set/get, Remixcontext.Scope
Works in all code paths:
api-handler.ts)pages-server-entry.ts)Changes
shims/unified-request-context.tsuserStore: Map<string, unknown>toUnifiedRequestContext+ default increateRequestContext()shims/request-store.tsgetRequestStore()public APIserver/api-handler.tsrunWithRequestContext(dev server)entries/pages-server-entry.ts_runWithUnifiedCtx(prod/Workers)package.json"./request-store"exportMotivation
We're running a production SaaS on vinext + Cloudflare Workers (Free plan) with Prisma v7 + Hyperdrive + R2 + NextAuth. We hit the exact alternating-failure pattern from #537 and initially worked around it with a 50ms TTL heuristic. This PR provides the proper framework-level solution.
vinext already has the
UnifiedRequestContext+AsyncLocalStorageinfrastructure. This PR exposes it to users via a clean public API — 73 lines across 5 files, zero breaking changes.Test plan
Closes #537
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.