mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #501] [MERGED] fix: use AsyncLocalStorage for per-request i18n locale state #623
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#623
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/501
Author: @NathanDrake2406
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/12/2026
Merged by: @james-elicx
Base:
main← Head:fix/i18n-locale-als📝 Commits (1)
33969edfix: use AsyncLocalStorage for per-request i18n locale state📊 Changes
8 files changed (+944 additions, -660 deletions)
View changed files
📝
packages/vinext/src/entries/pages-server-entry.ts(+17 -11)📝
packages/vinext/src/index.ts(+2 -0)📝
packages/vinext/src/server/dev-server.ts(+656 -625)➕
packages/vinext/src/shims/i18n-context.ts(+74 -0)➕
packages/vinext/src/shims/i18n-state.ts(+65 -0)📝
packages/vinext/src/shims/link.tsx(+4 -3)📝
tests/__snapshots__/entry-templates.test.ts.snap(+17 -11)📝
tests/link.test.ts(+109 -10)📄 Description
Summary
locale,defaultLocale,domainLocales,hostname) was stored on bareglobalThisproperties shared across concurrent requests<Link>components to produce incorrect locale-prefixed URLsrouter-state.ts/head-state.tspattern:i18n-context.ts: bridge module with fallbackglobalThisaccessors and a registration API (safe for both client and server import)i18n-state.ts: server-only module that registers ALS-backed accessors on import, providing per-request isolationlink.tsxnow reads locale context viagetI18nContext()instead of bareglobalThisssrLoadModule("vinext/i18n-context")to set context on the SSR module instance (matching the existingsetSSRContextpattern)runWithI18nState()and callssetI18nContext()Test plan
setI18nContextAPIdefaultLocalevalues produce correct locale prefixes (non-default gets prefix, default does not)link.test.ts,features.test.ts,shims.test.ts,entry-templates.test.ts,safe-json.test.ts)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.