Skip to content

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

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

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

Conversation

@bglgwyng
Copy link
Copy Markdown

@bglgwyng bglgwyng commented Mar 16, 2026

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() now, so there's a single restart path.

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

Background

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

What this PR does

Implements the approach suggested in #3380 and unblocks the commented-out code in #3583:

  1. Adds restartApp() and onAppRestart() to @electron-forge/core-utils, backed by a module-scoped EventEmitter. Plugins call restartApp() to signal a restart; the start API registers the actual kill→respawn logic via onAppRestart().
  2. Replaces the commented-out process.stdin.emit('data', 'rs') in pluginHotRestart with restartApp().
  3. The existing rs stdin handler also calls restartApp() instead of duplicating the restart logic, so both paths converge.

@bglgwyng bglgwyng requested a review from a team as a code owner March 16, 2026 06:20
@erickzhao erickzhao self-requested a review March 16, 2026 18:56
bglgwyng and others added 3 commits March 23, 2026 16:02
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>
@bglgwyng bglgwyng force-pushed the feat/hot-restart-exported-api branch from 6c0c50e to 76aceb1 Compare March 23, 2026 07:02
@bglgwyng
Copy link
Copy Markdown
Author

Do we need more approvals to merge this PR?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants