[plugin-rsc] With two dev servers in one process, loadModule runs in the last server's environment

オープン
#1,589 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
react, typescript, vite
領域
backend, devtools

調査の方向性

Start in the plugin-rsc package, where each server's configureServer sets globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__, and trace how import.meta.viteRsc.loadModule chooses the runner. Use the linked reproduction's repro.mjs to check behavior with two middleware mode servers, including after one closes. Done means each server's loadModule uses its own environment and continues working when the other server closes.

索引モデルが issue の本文から書いたものです。

説明

Related plugins
Describe the bug

Written with the help of an AI coding agent (Claude); reproduced locally.

Each dev server's configureServer sets globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ to a function bound to that server, and nothing resets it on close. With two servers in one process (e.g. tests), import.meta.viteRsc.loadModule in server A goes through server B:

server A, alone:           app a, evaluated by server A
server A, B started:       app a, evaluated by server B
server B:                  app b, evaluated by server B
server A, after B closed:  Error: Vite module runner has been closed.

evaluatedBy is set through each server's define, so A's ssr entry is evaluated in B's ssr environment, and A fails once B closes.

Reproduction

https://github.com/Sheraff/vite-plugin-rsc-two-dev-servers

Steps to reproduce
npm install
npm run repro

repro.mjs creates two middleware-mode servers (app-a, app-b, rsc({ serverHandler: false }), different define), and in each calls an rsc-entry function that does:

const ssr = await import.meta.viteRsc.loadModule('ssr', 'index')
return `app ${ssr.appName}, evaluated by ${ssr.evaluatedBy}`

Expected: evaluated by server A for every call on server A, and no error after server B closes.

A possible fix: key the dev runner import by server (an id in the transform output, falling back to the documented global when a framework overrides it), or at least restore the previous value when a server closes.

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: 41.36 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
  npmPackages:
    @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.4.0 => 8.4.0
Used Package Manager

npm

Logs

No response

Validations
主要言語
TypeScript
スター
1.2k
フォーク
287
平均マージ
1日 19時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vitejs/vite-plugin-react のほかの issue

vitejs/vite-plugin-react の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。