fix: send server environments their reload signal on hot update#282
Open
brenelz wants to merge 1 commit into
Open
fix: send server environments their reload signal on hot update#282brenelz wants to merge 1 commit into
brenelz wants to merge 1 commit into
Conversation
Returning [] from hotUpdate for non-client environments suppresses the full-reload messages that would race client HMR, but it also suppresses the only signal environment-runner based servers (e.g. nitro's dev worker) have for re-evaluating modules: with the modules array emptied, Vite's dead-end propagation never fires the environment-level full-reload, so SSR keeps serving stale modules until the dev server is restarted — and hydration mismatches against the freshly HMR-updated client. Keep the suppression, but send the reload on the environment's own hot channel first. For runner-based environments that channel reaches the runner; for the default ssr environment it is a no-op; it is never the browser websocket, so client HMR stays free of full-reload races.
|
commit: |
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.
Problem
hotUpdatereturns[]for every non-client environment. The intent (per the comment) is sound: solid-refresh only injects HMR boundaries into client modules, so letting Vite's propagation run in server environments dead-ends intofull-reloadmessages that race client-side HMR.But emptying the modules array also suppresses the only reload signal that environment-runner based servers rely on. With nitro's Vite integration (
nitro/vite), SSR runs in a persistent module runner inside a dev worker — evaluated modules live until that environment's hot channel receives afull-reload. Vite's default dead-end propagation would send exactly that, but it never runs because the modules array arrives empty (and downstream plugins like nitro's ownhotUpdateare blinded the same way, since Vite feeds each hook the previous hook's filtered array).Net effect in a
vite-plugin-solid+nitroapp: edit any SSR-rendered module (every route component) → client updates via HMR, server keeps rendering the old module until a manual dev-server restart → hydration key/markup mismatches on the next load (unclaimed server nodes, and in our repro aCannot read properties of null (reading 'nextSibling')crash during hydration).Full investigation with traces: nitrojs/nitro#4472 (this plugin's role: comment). The staleness also needs a nitro-side fix for its worker reload (nitrojs/nitro#4473) — but without this change, the reload is never even requested.
Fix
Keep the suppression, but send
{ type: "full-reload" }on the environment's own hot channel first (when the changed file has modules in that environment's graph):ssrenvironment, the channel is a no-op — nothing changes.Verification
Reproduced and verified against a Solid 2 +
nitro/viteplayground (vite 8.0.10, vite-plugin-solid 3.0.0-next.15, nitro 3.0.260610-beta with the nitrojs/nitro#4473 fix applied):pnpm build(rollup + tsc) passes.