Skip to content

fix(plugin-vite): restart the app on main rebuilds in electron-forge start - #4449

Open
a5768549 wants to merge 1 commit into
electron:mainfrom
a5768549:fix/vite-hot-restart-watch-worker
Open

a5768549 wants to merge 1 commit into
electron:mainfrom
a5768549:fix/vite-hot-restart-watch-worker

Conversation

@a5768549

@a5768549 a5768549 commented Oct 21, 2026 •

Copy link
Copy Markdown
  • 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:

Fixes #4446.

During electron-forge start, main and preload targets are built in a watch subprocess (spawnViteBuildWatch), and two things kept hotRestart from working there, as described in the issue:

  1. serializableConfig only passed build and renderer to the worker, so pluginHotRestart('restart') was never added to main targets.
  2. Even with it added, requestAppRestart() ran inside the worker, where no restart handler is registered; setAppRestartHandler runs in the parent's start().

Changes:

  • serializableConfig also passes hotRestart, and the comment that said workers only run when packaging is updated.
  • When pluginHotRestart('restart') runs in the watch subprocess (FORGE_VITE_WATCH=1), it sends { type: 'restart' } to the parent on rebuilds (not on the first build, and not when the build failed), the same way preload targets send reload-renderers.
  • spawnViteBuildWatch handles restart by calling requestAppRestart(), and warns if it isn't honored. The warning is shared through a small warnAppNotRestarted() helper so the in-process and subprocess paths print the same message.

Tests

  • vite.base.config.spec.ts: in the watch subprocess, pluginHotRestart('restart') sends restart to the parent only after a rebuild and doesn't call the local handler; a failed rebuild sends nothing.
  • subprocess-worker.spec.ts: a main target with hotRestart: true in watch mode sends only first-build-done for the first build, then restart after its entry changes.
  • Both new specs fail with the src/ changes reverted and pass with them.
  • yarn vitest run --project fast packages/plugin/vite/spec/ passes, except getBuildDefine:serve with custom server host, which fails the same way on an unmodified main on my machine (Windows 11, Node 24). oxfmt --check, oxlint and knip are clean.

The fix for #4439 is sent separately. Both PRs are based on main and apply on their own; they only overlap in subprocess-worker.spec.ts, where each adds a test, so whichever lands second may need a trivial rebase there.

…start

Main and preload targets are built in a watch subprocess during start, but
the worker never received hotRestart, so pluginHotRestart('restart') was not
added to main targets. Even with it added, requestAppRestart() would run in
the worker, where no restart handler is registered.

Pass hotRestart to the worker, and have pluginHotRestart ask the parent to
restart the app on rebuilds when it runs in the watch subprocess, the same
way preload targets ask it to reload the renderers.

Fixes electron#4446

Co-Authored-By: Claude <noreply@anthropic.com>
@a5768549
a5768549 requested a review from a team as a code owner October 21, 2026 20:02

This branch has not been deployed

No deployments
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.

plugin-vite 8.0.1: hotRestart never restarts the app during electron-forge start

1 participant