[bundledDev] React Fast Refresh endpoint returns index.html instead of JavaScript

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

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

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

  • #1481 @yousefissa による — マージされずにクローズ

評価

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

調査の方向性

Start with the linked reproduction and its vite.config.js, then run the documented curl request to /@react-refresh with bundledDev enabled and disabled. Check how the endpoint response differs; done means it returns the React Fast Refresh runtime as JavaScript, or reports an explicit documented limitation rather than returning index.html.

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

説明

plugin: react plugin: react-swc
Describe the bug

When using Vite 8's experimental bundledDev mode together with @vitejs/plugin-react, the /@react-refresh endpoint returns the bundled application index.html instead of the React Fast Refresh runtime JavaScript.

This is reproducible in a minimal Vite + React project without Module Federation.

The response is successful from an HTTP perspective (200 OK), but the content type and response body are incorrect for a JavaScript runtime endpoint. This causes integrations that import the React Refresh runtime to
receive HTML instead of JavaScript.

In our Module Federation setup, a React Remote's refresh proxy imports the Host's /@react-refresh URL. When the Host uses bundledDev, that import receives index.html and fails with:

TypeError: Failed to fetch dynamically imported module:
http://127.0.0.1:5173/@react-refresh

The Module Federation integration is not required to reproduce the Vite endpoint behavior; it only exposes the incompatibility in an integration scenario.

Reproduction

https://github.com/dmchoi77/vite-bundleddev-react-refresh-repro

Steps to reproduce
  1. Clone the reproduction repository:

    git clone https://github.com/dmchoi77/vite-bundleddev-react-refresh-repro.git
    cd vite-bundleddev-react-refresh-repro
    
  2. Install the dependencies:

    npm install
    
  3. Start the Vite development server:

    npm run dev
    
  4. In another terminal, request the React Fast Refresh endpoint:

    curl -i http://127.0.0.1:5173/@react-refresh
    
  5. Compare the response with bundledDev disabled:

    • Change bundledDev: true to bundledDev: false in vite.config.js.
    • Restart the development server.
    • Run the same curl command again.

Actual result

With experimental.bundledDev: true, the endpoint returns the application
HTML document:

HTTP/1.1 200 OK
Content-Type: text/html

The response body contains index.html, including the bundled entry script:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite bundledDev React refresh repro</title>
    <script type="module" crossorigin src="/assets/index.js"></script>
  </head>

It does not contain the React Fast Refresh runtime JavaScript.

Expected result

The /@react-refresh endpoint should return the React Fast Refresh runtime as
JavaScript when @vitejs/plugin-react is enabled.

If React Fast Refresh is intentionally unsupported in bundledDev mode, the
endpoint should instead expose an explicit documented behavior or error so
that integrations can detect the limitation without receiving a successful
HTML fallback response.

For comparison, the same reproduction with experimental.bundledDev: false
returns the expected JavaScript response:

HTTP/1.1 200 OK
Content-Type: text/javascript
System Info
npmPackages:
    @vitejs/plugin-react: 6.0.2 => 6.0.2
    vite: 8.2.0 => 8.2.0
Used Package Manager

npm

Logs

The endpoint response with bundledDev: true:

HTTP/1.1 200 OK
Vary: Origin
Content-Type: text/html
Cache-Control: no-cache

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite bundledDev React refresh repro</title>
    <script type="module" crossorigin src="/assets/index.js"></script>

The related Module Federation integration error is:

TypeError: Failed to fetch dynamically imported module:
http://127.0.0.1:5173/@react-refresh
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 を短くまとめたダイジェスト。