cloudflare / cloudflare/workers-sdk
@cloudflare/vite-plugin: editing index.html restarts the dev server and races the page reload
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 187
Description
### Which Cloudflare product(s) does this pertain to?
`@cloudflare/vite-plugin`
### What version(s) of the tool(s) are you using?
`@cloudflare/vite-plugin@1.54.0` (also present in the published `1.54.4`), `vite@8.2.2`, `wrangler@4.126.0`
### What version of Node are you using?
24
### Describe the Bug
Editing the client's `index.html` restarts the entire Vite dev server, while Vite simultaneously sends the browser a `page reload`. The reload lands on a server that is still restarting, so the tab hangs instead of showing the change. A plain `vite` dev server (plugin removed) does a clean `page reload index.html` for the same edit.
The cause looks like `additional-modules.ts`: `.html` is one of the `Text` module rules, and the hot-update hook restarts the server for any path in `additionalModulePaths`:
```js
const moduleRules = [
{ type: "CompiledWasm", pattern: /\.wasm(\?module)?$/ },
{ type: "Data", pattern: /\.bin$/ },
{ type: "Text", pattern: /\.(txt|html|sql)$/ },
];
hotUpdate(options) {
if (additionalModulePaths.has(options.file)) {
options.server.restart();
return [];
}
}
```
A restart is correct for a `.html` / `.txt` / `.sql` file the Worker imports, since it is baked into the Worker bundle at startup. The client's own HTML entry ends up in the same set, and for it a restart is both unnecessary and actively harmful, because it races Vite's own page reload.
Server log with the plugin enabled, after `touch index.html`:
```
@CLOUDFLARE:VITE-PLUGIN 72290: From server.restart(): Restarting server...
[vite] (client) page reload index.html
[vite] server restarted.
```
Same edit with the plugin removed:
```
[vite] (client) page reload index.html
```
A Worker-imported `.html` (`import template from './authorize-page.html?raw'`) produces the identical restart signature, which is the expected behaviour for that file.
### Please provide a link to a minimal reproduction
No response
### Please provide any relevant error logs
Repro on any Worker + SPA app created with the plugin:
1. `vite dev`
2. Open the app in a browser.
3. Edit `index.html` (a whitespace change is enough).
4. The dev server restarts and the browser's reload hangs until the server is back.
Locally patching the hook to skip the Vite root's `index.html` fixes it and leaves Worker-imported text modules restarting as before.
Contributor guide
Research direction
Start in additional-modules.ts at the module rules and hot-update hook, then reproduce the issue by editing a client index.html in a Worker + SPA app. Confirm that the client HTML reloads without restarting the Vite server, while Worker-imported text modules such as authorize-page.html?raw still trigger the expected restart.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 76/100