Repository navigation
Open
Description
Pre-flight checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project uses.
- I have searched the issue tracker for a bug that matches the one I want to file, without success.
Forge version
8.0.1
Electron version
v44.5.1
Operating system
macOS 26.6.2 (arm64)
Last known working Forge version
No response
Expected behavior
With hotRestart: true in the Vite plugin config, a change to the main process entry during electron-forge start rebuilds the bundle and restarts the running app.
Actual behavior
The main bundle is rebuilt ([@electron-forge/plugin-vite] target built src/main/index.ts), but the app is not restarted and keeps running the previous code. No "Restarting Electron app" line appears.
Steps to reproduce
- A Vite-template project with
new VitePlugin({ hotRestart: true, build: [{ entry: 'src/main/index.ts', config: 'vite.main.config.ts', target: 'main' }, ...], renderer: [...] }). - Run
electron-forge start. - Change
src/main/index.ts. The target is rebuilt; the app keeps its process and old code.
Additional information
In dev mode, main and preload targets are built in a watch subprocess (spawnViteBuildWatch). Two things keep the restart from happening:
VitePlugin.serializableConfigpasses onlybuildandrendererto the worker. Its comment says "hotRestartis moot here: workers only run when packaging", but the watch builds ofstartrun there too. SopluginHotRestart('restart')is never added to the worker's Vite config.- Even with it added,
pluginHotRestartcallsrequestAppRestart()inside the worker, where no restart handler is registered (setAppRestartHandlerruns in the parent'sstart()). The worker already forwardsreload-renderersto the parent for preload targets; nothing similar exists forrestart.
This patch fixes it for us:
--- a/dist/VitePlugin.js
+++ b/dist/VitePlugin.js
import { readJson, writeJson } from '@electron-forge/core-utils';
+import { requestAppRestart } from '@electron-forge/core-utils/restart';
@@ spawnViteBuildWatch
else if (msg.type === 'reload-renderers') {
onReloadRenderers();
}
+ else if (msg.type === 'restart' && !requestAppRestart()) {
+ console.warn(styleText('yellow', '[@electron-forge/plugin-vite] Rebuilt the main process bundle, but the running app was not restarted, so it is still running the previous code.'));
+ }
@@ get serializableConfig()
return {
build: this.config.build,
renderer: this.config.renderer,
+ hotRestart: this.config.hotRestart,
};
--- a/dist/config/vite.base.config.js
+++ b/dist/config/vite.base.config.js
@@ pluginHotRestart, closeBundle
+ else if (command === 'restart' && isRebuild && process.send) {
+ // In the watch subprocess the restart handler lives in the parent; ask it.
+ process.send({ type: 'restart' });
+ }
else if (command === 'restart' && !requestAppRestart() && isRebuild) {Reacted by Uaena_Alex_John and Ian Chadwick
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(plugin-vite): restart the app on main rebuilds in electron-forge …
chore(setup): setup HMR to main process, but exists a bug waiting to …
chore(setup): setup HMR to main process, but exists a bug waiting to …
chore(setup): setup HMR to main process, but exists a bug waiting to …
chore(setup): setup HMR to main process, but exists a bug waiting to …
fix(plugin-vite): restart the app on main rebuilds in electron-forge …