Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

fix: don't send browser full-reload for server-only modules by default#4034

Open
schiller-manuel wants to merge 1 commit intomainfrom
no-browser-reload-hmr
Open

fix: don't send browser full-reload for server-only modules by default#4034
schiller-manuel wants to merge 1 commit intomainfrom
no-browser-reload-hmr

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Feb 13, 2026

hotUpdate hook was unconditionally sending server.ws.send full-reload when any server-only module was detected, destroying client-side HMR. Split modules into server-only vs shared, only browser-reload when ALL modules are server-only and serverReload is explicitly enabled (default changed from true to false).

closes TanStack/router#5904

@schiller-manuel schiller-manuel requested a review from pi0 as a code owner February 13, 2026 21:41
@vercel
Copy link

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Feb 13, 2026 10:37pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

hotUpdate in the Vite Nitro plugin now classifies changed modules into server-only and shared sets, invalidates server-only modules, and triggers browser full-reloads only when server-only modules exist (honoring the experimental/serverReload flag). Documentation for serverReload was clarified and its default annotation changed; an example config and E2E tests were added.

Changes

Cohort / File(s) Summary
HMR Module Classification
src/build/vite/plugin.ts
Reworked hotUpdate: removed the prior client+server early-exit, replaced a boolean with serverOnlyModules and sharedModules, invalidate server-only modules, decide full-reload based on serverOnlyModules.length, optionally send a server WS full-reload when there are no shared modules and experimental.vite.serverReload is enabled, and return sharedModules for downstream HMR handling.
Configuration Documentation
src/build/vite/types.ts
Updated docs for NitroPluginConfig.serverReload to specify "Reload the browser page when a server-only module is updated", added explanatory text about invalidation vs browser reload and client-side HMR preservation, and changed the @default annotation from true to false.
Example Config
examples/vite-ssr-react/vite.config.server-reload.mjs
Added example Vite config enabling the Nitro plugin with experimental serverReload and React plugin; defines a client build input.
Hot-update Tests
test/hot-update.test.ts
Added E2E tests that spin up dev servers (default and serverReload enabled), simulate edits to shared and server-only modules, collect Vite WS messages, assert full-reload behavior per configuration, verify served updates, and clean up servers/files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows the conventional commits format with a 'fix:' prefix and clearly describes the main change of not sending browser full-reload for server-only modules by default.
Linked Issues check ✅ Passed The pull request fully addresses the linked issue #5904 by preventing unwanted full-page reloads when editing routes with server functions, preserving client-side HMR for mixed modules.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the HMR issue: plugin logic refactoring, configuration updates, example config for serverReload, and comprehensive end-to-end tests validating the fix.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description check ✅ Passed The pull request description directly addresses the changeset by explaining the core fix: preventing unconditional server full-reloads for server-only modules while preserving client-side HMR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch no-browser-reload-hmr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@4034

commit: f545c4d

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/build/vite/plugin.ts`:
- Around line 262-268: The conditional uses
ctx.pluginConfig.experimental?.vite.serverReload which can throw if experimental
exists but vite is undefined; update the check to safely optional-chain through
vite (e.g., ctx.pluginConfig.experimental?.vite?.serverReload) so access to
serverReload is guarded; locate the block around serverOnlyModules/sharedModules
and change the experimental?.vite.serverReload usage in that if-statement to use
?.vite?.serverReload.

hotUpdate hook now separates server-only vs shared modules.
Browser full-reload only sent when serverReload option is true (default false).
Shared modules continue through normal HMR pipeline.
Adds e2e tests for both default (no reload) and serverReload:true behaviors.
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.

HMR is broken in route with server function using nitro v3 plugin

1 participant