Skip to content

fix(plugin-vite): don't reload renderers after the first preload build - #4448

Open
a5768549 wants to merge 1 commit into
electron:mainfrom
a5768549:fix/vite-preload-first-build-reload
Open

a5768549 wants to merge 1 commit into
electron:mainfrom
a5768549:fix/vite-preload-first-build-reload

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 #4439.

During electron-forge start, the preload watch build asked the parent to send a full-reload from closeBundle on every build, including the first one. The first build finishes before Electron is spawned, so no client is connected yet. Vite buffers a full-reload that finds no client and delivers it to the first client that connects, so the window's page reloads right after it first loads.

subprocess-worker.ts now only forwards reload-renderers for rebuilds, the same way pluginHotRestart uses builtOnce.

Tests

  • Added a subprocess-worker spec that runs a preload target in watch mode, copied to a temp dir, and records the IPC messages: the first build sends only first-build-done, and appending to the preload entry then sends reload-renderers. It fails on main (the first build also sends reload-renderers) and passes with this change.
  • yarn vitest run --project fast packages/plugin/vite/spec/ passes, except getBuildDefine:serve with custom server host in vite.base.config.spec.ts, which fails the same way on an unmodified main on my machine (Windows 11, Node 24).
  • oxfmt --check and oxlint are clean for packages/plugin/vite.

The fix for #4446 is separate and sent as its own PR. Both add a test to subprocess-worker.spec.ts, so whichever lands second may need a trivial rebase there.

The preload watch build asked the parent to send a full-reload on every
build, including the first one. That build finishes before Electron starts,
so no client is connected, and Vite buffers the message and delivers it to
the first client that connects, reloading the page right after it loads.

Only forward reload-renderers for rebuilds, like pluginHotRestart does with
builtOnce.

Fixes electron#4439

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: electron-forge start loads the renderer twice, as the first preload build sends a full-reload

1 participant