Dependency Optimizer: re-optimization can flip which duplicated chunk is "canonical" for a module, breaking module singletons (duplicate React on a cold-started dev server)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- react, typescript, vite
- 領域
- build-system, tooling
調査の方向性
まず、リンクされている duplicate-react-cold-start の再現とその README から始め、次に Vite の dependency-optimization re-optimization path と chunk canonicalization を追跡します。完了条件は、オプティマイザーのパスを繰り返しても canonical mapping が安定したままになり、再現で重複した React インスタンスや初回レンダー時の invalid hook call が発生しなくなることです。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
🤖 AI Disclosure: Claude Code has written up majority of this issue and most of the reproduction README. I, as a human, still take responsibility for it.
Summary
When two optimizeDeps.include entries resolve to the same module (e.g. react and @vitejs/plugin-rsc > react, where @vitejs/plugin-rsc can be any package that peer-depends on react), the optimizer emits two chunks for it — one holds the real module, the other re-exports it. Which one is "canonical" vs. the re-export is not stable across optimizer passes: a re-optimization can swap them.
| chunk | pass 1 (cold) | pass 2 (after re-optimization) |
|---|---|---|
react.js |
canonical | alias → @vitejs_plugin-rsc_n_react.js |
@vitejs_plugin-rsc_n_react.js |
alias → react.js |
canonical |
If that re-optimization is triggered after some modules have already been served (a dependency discovered at request time), a consumer loaded before the swap and one loaded after end up bound to two different real instances of the module. For React this is Invalid hook call / Cannot read properties of null (reading 'useState'); the page then auto-reloads (optimized dependencies changed. reloading) and the error vanishes — so it's cold-start-only, first-render-only.
Detailed explanation can be found in the reproduction repository's README.
Context
I've been developing a React framework based on @vitejs/plugin-rsc. This issue originally surfaced as a framework bug, but a thorough investigation made us believe that this is a Vite issue.
The repro still uses @vitejs/plugin-rsc because it is the way we are aware of for reliably reproducing the issue, but we believe this issue is in Vite's Deps Optimization, hence a bug report in this repo.
The trigger path (via @vitejs/plugin-rsc): a "use client" package imported by a server component is reached on the browser through a request-time virtual:vite-rsc/client-package-proxy/<pkg> module that the optimizer's initial scan can't follow — so the package (and the React it imports) is discovered on the first render and forces the re-optimization.
Side Note: possible another form of this bug
Initially this bug surfaced as a different error like this:
The requested module '/node_modules/.vite/deps/react_jsx-runtime.js?v=...' does not provide an export named 't'
a severer ES Modules link time error. This version of error is not included in this bug report because (1) we couldn't reproduce this without involving our framework and (2) we are not sure whether they are truly same origin. Read more about this at https://github.com/uhyo/funstack-static/issues/124 and https://github.com/uhyo/funstack-static/issues/128.
Reproduction
https://github.com/uhyo/vite-rsc-deps-issue-repro/tree/repro/duplicate-react-cold-start
Steps to reproduce
pnpm install && rm -rf node_modules/.vite && pnpm dev
# open the URL; first load throws Invalid hook call, then auto-reloads
System Info
System:
OS: Linux 6.18 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 PRO 6850U with Radeon Graphics
Memory: 12.37 GB / 15.01 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 24.13.1 - /home/uhyo/.volta/tools/image/node/24.13.1/bin/node
Yarn: 4.1.1 - /home/uhyo/.volta/tools/image/yarn/4.1.1/bin/yarn
npm: 11.4.2 - /home/uhyo/.volta/tools/image/npm/11.4.2/bin/npm
pnpm: 10.30.1 - /home/uhyo/.volta/bin/pnpm
Deno: 2.2.1 - /home/uhyo/.deno/bin/deno
npmPackages:
@vitejs/plugin-react: latest => 6.0.3
@vitejs/plugin-rsc: latest => 0.5.27
vite: ^8.0.16 => 8.1.0
Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
- 主要言語
- TypeScript
- スター
- 1.2k
- フォーク
- 287
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 21
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vitejs/vite-plugin-react のほかの issue
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)対応中かも @wozhenbang2004 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
vitejs/vite-plugin-react#1570 ·
メンテナーはふだん 1 日以内に返信
-
[plugin-rsc] With two dev servers in one process, loadModule runs in the last server's environmentオープン
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
vitejs/vite-plugin-react#1589 ·
メンテナーはふだん 1 日以内に返信
-
pending triage
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
vitejs/vite-plugin-react#1581 ·
メンテナーはふだん 1 日以内に返信
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC build対応中かも @NeilPant が 4 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
vitejs/vite-plugin-react#1578 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
vitejs/vite-plugin-react#1577 ·
メンテナーはふだん 1 日以内に返信
vitejs/vite-plugin-react の issue をすべて見る
似ている issue
-
bug from-app needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nightly-labs/openbot#18462 ·
メンテナーはふだん 1 日以内に返信
-
Fast and light shell approval "Always allow" button shows raw English backticks and scrambles commands in Arabic対応中かも @tylerbea が今日担当しました。 オープンagent-ui bug p3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
[Bug] Windows: Ctrl+C / Ctrl+V not working in chat input box対応中かも @PranavTJ-05 が今日担当しました。 オープンcomp/desktop desktop/chat desktop/shell os/windows P2 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
NousResearch/hermes-agent#161023 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
resources
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
railmapgen/rmg-templates#2703 ·
メンテナーはふだん 1 日以内に返信
-
TypeScript OSS: `huggingfaceBaseUrl` is dropped by config validation, so the documented HuggingFace embedder example throws対応中かも @jaisogani-ai が今日担当しました。 オープンbug sdk-typescript
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信