Skip to content

fix: avoid duplicate client HMR updates#15319

Open
wanxiankai wants to merge 2 commits into
remix-run:mainfrom
wanxiankai:fix/hmr-duplicate-evaluations
Open

fix: avoid duplicate client HMR updates#15319
wanxiankai wants to merge 2 commits into
remix-run:mainfrom
wanxiankai:fix/hmr-duplicate-evaluations

Conversation

@wanxiankai

Copy link
Copy Markdown

Fixes #13774

What changed

  • restrict the server-to-client HMR bridge to the SSR environment
  • skip modules that already receive Vite's native client HMR update
  • deduplicate client parent modules reached from server-only changes
  • add a browser evaluation-count regression covering Vite 7 and Vite 8, both with the built-in dev server and Express
  • add the required patch change file and CLA signature

Why

Vite invokes the hotUpdate hook for separate client and SSR environments. The React Router bridge also ran in the client environment and reloaded modules already present in the client graph. As a result, a single source edit evaluated the route module multiple times and could trigger unrelated updates.

The bridge now only propagates changes from SSR-only modules. Client modules continue to use Vite's native HMR path, while server-only loader dependencies still walk to and reload their client parents.

The regression reproduced four total browser evaluations (initial load plus three updates) before the fix and now verifies exactly two (initial load plus one update).

Verification

  • pnpm build
  • pnpm typecheck
  • pnpm lint (0 errors)
  • pnpm test --no-watchman (2,629 passed, 15 skipped)
  • pnpm test:integration:run --project=chromium vite-hmr-hdr-test.ts (6 passed)
  • pnpm format:check
  • git diff --check

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 evaluates multiple times

1 participant