Repository navigation
Conversation
…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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summarize your changes:
Fixes #4446.
During
electron-forge start, main and preload targets are built in a watch subprocess (spawnViteBuildWatch), and two things kepthotRestartfrom working there, as described in the issue:serializableConfigonly passedbuildandrendererto the worker, sopluginHotRestart('restart')was never added to main targets.requestAppRestart()ran inside the worker, where no restart handler is registered;setAppRestartHandlerruns in the parent'sstart().Changes:
serializableConfigalso passeshotRestart, and the comment that said workers only run when packaging is updated.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 sendreload-renderers.spawnViteBuildWatchhandlesrestartby callingrequestAppRestart(), and warns if it isn't honored. The warning is shared through a smallwarnAppNotRestarted()helper so the in-process and subprocess paths print the same message.Tests
vite.base.config.spec.ts: in the watch subprocess,pluginHotRestart('restart')sendsrestartto 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 withhotRestart: truein watch mode sends onlyfirst-build-donefor the first build, thenrestartafter its entry changes.src/changes reverted and pass with them.yarn vitest run --project fast packages/plugin/vite/spec/passes, exceptgetBuildDefine:serve with custom server host, which fails the same way on an unmodifiedmainon my machine (Windows 11, Node 24).oxfmt --check,oxlintandknipare clean.The fix for #4439 is sent separately. Both PRs are based on
mainand apply on their own; they only overlap insubprocess-worker.spec.ts, where each adds a test, so whichever lands second may need a trivial rebase there.