mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #532] [MERGED] fix: concurrent SSR isolation for pages router head/router state #652
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#652
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/532
Author: @aidantrabs
Created: 3/13/2026
Status: ✅ Merged
Merged: 3/15/2026
Merged by: @james-elicx
Base:
main← Head:feat/als-phase2-parity-tests📝 Commits (10+)
0034a09test: add concurrent ssr isolation fixture pages for pages router1f8891atest: add pages router dev concurrency isolation tests3069026fix: register head/router als accessors in ssr module graphe3d2a9ctest: add prod concurrency isolation tests2df5230docs: add als architecture and per call scope docs49635d0fix: move als accessor registration to one time setup in createSSRHandler07e9bd7test: add assertion messages and explicit guards for ci debugging4d2e6aftest: use lookahead in extractMetaContent for attribute order independence7f86a91test: add comment explaining prod head test limitations22958f0docs: clarify pr #450 wording in als architecture doc📊 Changes
8 files changed (+419 additions, -54 deletions)
View changed files
📝
packages/vinext/src/server/dev-server.ts(+16 -1)➕
packages/vinext/src/shims/ALS-ARCHITECTURE.md(+98 -0)📝
tests/__snapshots__/entry-templates.test.ts.snap(+56 -50)➕
tests/fixtures/pages-basic/pages/concurrent-head.tsx(+26 -0)➕
tests/fixtures/pages-basic/pages/concurrent-router.tsx(+31 -0)📝
tests/helpers.ts(+6 -2)➕
tests/pages-router-concurrency.test.ts(+180 -0)📝
tests/pages-router.test.ts(+6 -1)📄 Description
Closes #478 (first follow-up PR)
summary
<Head>elements leaked between concurrent dev requests becausehead-state.tsals accessors were only registered in vite's node module graph, not the ssr module graph where theHeadcomponent runsssrLoadModulecalls forvinext/head-stateandvinext/router-statein dev-server.ts to register als-backed accessors in the correct environmentcacheContextStorageand_unstableCacheAlsseparate from the unified context - they are per-call, not per-requestwhat changed
packages/vinext/src/server/dev-server.ts- load head-state and router-state in the ssr module graph before renderingtests/fixtures/pages-basic/pages/concurrent-head.tsx- fixture page that sets<Head>title and meta from a query paramtests/fixtures/pages-basic/pages/concurrent-router.tsx- fixture page that echoes ssr pathname and query from getServerSideProps and useRoutertests/pages-router-concurrency.test.ts- dev and prod concurrency testspackages/vinext/src/shims/ALS-ARCHITECTURE.md- architecture docswhy
vite's dev server has separate module graphs for node and ssr environments.
static imports in dev-server.ts load into the node graph, but react components render in the ssr graph. the
head-state.tsregistration was only happening in the node graph, so the ssr copy ofhead.tskept using a shared module-level array for<Head>children. every concurrent request pushed into the same array.the prod server doesn't have this problem because bundling collapses everything into one module graph.
test plan
pnpm test tests/pages-router-concurrency.test.ts- 4 tests passpnpm run fmt:check- cleanpnpm run lint- cleanpnpm run typecheck- cleannext steps (issue #478 part 2)
the issue outlines a second optional/conditional cleanup pr:
headers.ts,navigation-state.ts,cache.ts,cache-runtime.ts,fetch-cache.ts,request-context.ts,router-state.ts,head-state.ts,i18n-state.ts) and remove the ones that are no longer reachable now that the unified context is in place🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.