Skip to content

feat(plugin-vite): enable main process hot restart via exported API#4210

Open
bglgwyng wants to merge 4 commits intoelectron:nextfrom
bglgwyng:feat/hot-restart-exported-api-v2
Open

feat(plugin-vite): enable main process hot restart via exported API#4210
bglgwyng wants to merge 4 commits intoelectron:nextfrom
bglgwyng:feat/hot-restart-exported-api-v2

Conversation

@bglgwyng
Copy link
Copy Markdown

@bglgwyng bglgwyng commented Apr 9, 2026

Summary

Replaces #4168 with a clean branch based on next.

  • Add restartApp()/onAppRestart() to @electron-forge/core-utils as an explicit API for triggering Electron app restarts
  • The Vite plugin calls restartApp() in its closeBundle hook when the main process bundle is rebuilt
  • The start API registers the actual restart logic via onAppRestart()
  • The existing rs stdin handler also goes through restartApp(), so there's a single restart path
  • Hot restart is opt-in via hotRestart: true in the Vite plugin config

Background

Main process hot restart for the Vite plugin has been requested and attempted multiple times:

This PR implements the approach suggested in #3380 and unblocks the commented-out code in #3583.

Test plan

  • ViteConfig.spec.ts tests pass (hot restart plugin only included when hotRestart: true)
  • vite.base.config.spec.ts tests pass
  • Manual test: set hotRestart: true in Vite plugin config, modify main process code, verify app restarts
  • Manual test: without hotRestart config, verify no auto-restart on main process changes

🤖 Generated with Claude Code

bglgwyng and others added 4 commits April 9, 2026 14:39
Add restartApp()/onAppRestart() to @electron-forge/core-utils as an
explicit API for triggering Electron app restarts. The Vite plugin
calls restartApp() in its closeBundle hook when the main process
bundle is rebuilt. The start API registers the actual restart logic
via onAppRestart(). Also backport the duplicate restart guard
(!lastSpawned.restarted) to the stdin handler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The stdin 'rs' handler now calls restartApp() instead of duplicating
the kill→respawn logic, so all restart requests flow through the
single onAppRestart callback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevent unnecessary terminal cursor manipulation when the Electron app
has not been spawned yet.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `hotRestart` option to VitePluginConfig (default: false).
The main process restart is now only enabled when explicitly configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bglgwyng
Copy link
Copy Markdown
Author

I just tested it and it's really ready now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant