[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
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, nodejs, react, typescript, vite
調査の方向性
Start in packages/plugin-rsc/src/plugin.ts, around the buildApp scan that covers only the rsc and ssr environments (L478-L511), and trace when [4/5] build client environment runs. Reproduce with the linked repo via npm run repro versus npm run control; both print whether dist/rsc contains showInner and whether Inner reaches the client bundle. Done means repro renders <p>inner</p>, or at minimum the build fails naming the missing server reference.
索引モデルが issue の本文から書いたものです。
説明
Written with the help of an AI coding agent (Claude); reproduced locally.
Related plugins
Describe the bug
A 'use server' module that only browser code imports (here the browser entry) is first seen by the client build, after the RSC build:
// entry.browser.jsx
import '@vitejs/plugin-rsc/browser'
import { showInner } from './actions.jsx'
globalThis.showInner = showInner
// actions.jsx
'use server'
import { Inner } from './Inner.jsx' // 'use client'
export async function showInner() {
return <Inner />
}
Actual: vite build exits 0 with no warning. The client bundle calls fc5b8e0c47b4#showInner, dist/rsc has no showInner, and calling it fails with server reference not found 'fc5b8e0c47b4'. Inner is not in the client JS either.
Expected: the RSC build includes showInner (and the client build Inner), and the action renders <p>inner</p>. At least, vite build fails with an error naming the missing server reference.
A second complete vite build whose RSC entry also imports the 'use server' modules the first build's client environment transformed delivers both showInner and Inner (npm run control below).
buildApp scans rsc and ssr only, and nothing after [4/5] build client environment can add RSC modules:
https://github.com/vitejs/vite-plugin-react/blob/447ab6208f5fd85968e8307735e1198ea17148c2/packages/plugin-rsc/src/plugin.ts#L478-L511
Possible fix: a further discovery round (RSC, then client) when the client build finds server references the RSC build lacks, or a build error naming them.
Production build only; dev not tested. See also #1472 (a recognizable runtime error for unknown ids).
Related: same defect in Rspack's RSC plugin: https://github.com/web-infra-dev/rspack/issues/16786
Reproduction
https://github.com/Sheraff/vite-plugin-rsc-discovery-round-repro
Steps to reproduce
npm install
npm run repro # only the browser entry imports the action
npm run control # a server-rendered client component imports it; a second build seeded from the first
$ npm run repro
BUG browser only the browser entry imports the action
client calls: fc5b8e0c47b4#showInner
rsc build has showInner: no
Inner in client JS: no
showInner(): server reference not found 'fc5b8e0c47b4'
$ npm run control
OK rendered a client component the server renders imports it
rsc build has showInner: yes
Inner in client JS: yes
html: <p>inner</p>
OK browser second build, seeded from the first
rsc build has showInner: yes
Inner in client JS: yes
html: <p>inner</p>
Same with react 19.2.9, vite 7.3.8 (@vitejs/plugin-react 5.2.0), and the pkg.pr.new build of main (447ab62).
System Info
System:
OS: Linux 6.12 Debian GNU/Linux 13 (trixie) 13 (trixie)
CPU: (32) x64 AMD Ryzen 9 9955HX 16-Core Processor
Memory: 53.03 GB / 60.50 GB
Container: Yes
Shell: 5.2.37 - /bin/bash
Binaries:
Node: 26.12.1 - ~/.local/share/pnpm/bin/node
npm: 12.2.0 - ~/.local/share/pnpm/bin/npm
pnpm: 12.11.2 - ~/.local/share/pnpm/bin/pnpm
Browsers:
Chrome: 158.0.8127.36
npmPackages:
@vitejs/plugin-react: 6.3.0 => 6.3.0
@vitejs/plugin-rsc: 0.5.39 => 0.5.39
react: 19.3.1 => 19.3.1
react-dom: 19.3.1 => 19.3.1
vite: 8.3.8 => 8.3.8
Used Package Manager
npm
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.
- 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日 17時間
- マージ済み PR(30日)
- 19
環境構築
- 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 が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
vitejs/vite-plugin-react#1570 ·
メンテナーはふだん 1 日以内に返信
-
pending triage
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
vitejs/vite-plugin-react#1581 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
vitejs/vite-plugin-react#1577 ·
メンテナーはふだん 1 日以内に返信
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceError対応中かも @draarivpatel-ui が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
vitejs/vite-plugin-react#1566 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
vitejs/vite-plugin-react#1565 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
vitejs/vite-plugin-react の issue をすべて見る
似ている issue
-
ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mermaid-js/mermaid-v13#1370 ·
メンテナーはふだん 1 日以内に返信
-
compiler: the island_chunks_not_emitted report gives a count but not which islands were skippedオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
Broken Website
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
darkreader/darkreader#16259 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
メンテナーはふだん 1 日以内に返信