mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #413] [MERGED] fix: dedup RSC client references to prevent module duplication in dev #554
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#554
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/413
Author: @Divkix
Created: 3/10/2026
Status: ✅ Merged
Merged: 3/10/2026
Merged by: @james-elicx
Base:
main← Head:fix/client-reference-dedup📝 Commits (3)
7b82067fix: dedup RSC client references to prevent module duplication in dev439d2ecfix: make dedup test layout a server component to exercise RSC proxy path641653fdocs: address PR review feedback for client-reference-dedup plugin📊 Changes
11 files changed (+355 additions, -0 deletions)
View changed files
📝
packages/vinext/src/index.ts(+3 -0)➕
packages/vinext/src/plugins/client-reference-dedup.ts(+103 -0)📝
pnpm-lock.yaml(+8 -0)📝
tests/app-router.test.ts(+15 -0)➕
tests/client-reference-dedup.test.ts(+183 -0)➕
tests/fixtures/app-basic/__test_packages__/fake-context-lib/index.js(+1 -0)➕
tests/fixtures/app-basic/__test_packages__/fake-context-lib/internal/context.js(+14 -0)➕
tests/fixtures/app-basic/__test_packages__/fake-context-lib/package.json(+9 -0)➕
tests/fixtures/app-basic/app/context-dedup-test/layout.tsx(+5 -0)➕
tests/fixtures/app-basic/app/context-dedup-test/page.tsx(+13 -0)📝
tests/fixtures/app-basic/package.json(+1 -0)📄 Description
Summary
Fixes #409
When the RSC plugin creates
client-in-server-package-proxymodules for"use client"submodules within packages (e.g.,@mantine/core), it re-exports from absolute file paths. These bypass Vite's pre-bundling in the client environment, causing the browser to load two separate module instances — one from the raw ESM path and one from.vite/deps/. This breaks React context providers/consumers sincecreateContext()runs twice.vinext:client-reference-dedupplugin (enforce: "pre", dev-only) that intercepts absolutenode_modulespath imports originating from proxy virtual modules in the client environment and redirects them through bare specifier imports, which Vite's import analysis routes through pre-bundling automaticallyoptimizeDeps.excludefrom resolved config so user overrides are honoredTest plan
extractPackageName(regular, scoped, nested node_modules, edge cases)resolveId/loadhooks (client env gating, proxy importer gating, exclude list)fake-context-libfixture package (internal"use client"submodule withcreateContext— verifies provider value is readable by consumer)pnpm run typecheckpassespnpm run lintpassespnpm run fmt:checkpasses🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.