Skip to content

fix(hmr): stop unloaded-route edits from wedging browser HMR#6774

Open
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:wedging-issue
Open

fix(hmr): stop unloaded-route edits from wedging browser HMR#6774
FarhanAliRaza wants to merge 3 commits into
reflex-dev:mainfrom
FarhanAliRaza:wedging-issue

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

React Router queues manifest updates for lazy routes even when their modules aren't loaded in the browser. Its HMR runtime throws on those entries before clearing the queue, blocking every later hot update until a full page reload. Add a Vite plugin that patches the runtime to skip unloaded routes instead of throwing.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

React Router queues manifest updates for lazy routes even when their
modules aren't loaded in the browser. Its HMR runtime throws on those
entries before clearing the queue, blocking every later hot update
until a full page reload. Add a Vite plugin that patches the runtime to
skip unloaded routes instead of throwing.
@FarhanAliRaza FarhanAliRaza requested a review from a team as a code owner July 15, 2026 16:02
@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing FarhanAliRaza:wedging-issue (9d27690) with main (65a2889)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a browser HMR wedge in React Router by adding a Vite plugin that patches the react-router HMR runtime at serve time, replacing a throw on unloaded routes with a continue so the update queue is not poisoned by routes that haven't been loaded in the browser yet.

  • templates.py: Adds patchReactRouterHmrRuntime() as an enforce: "post" Vite plugin (serve-only) that regex-patches the virtual react-router/hmr-runtime module. Graceful degradation via this.warn() is included for when the upstream code changes.
  • test_hmr.py: Adds a new Playwright integration test that verifies: editing an unloaded route sends a manifest update, and a subsequent edit to the loaded index route still triggers a DOM hot-update (i.e., the queue is not wedged).

Confidence Score: 5/5

Safe to merge — the plugin only runs in dev/serve mode, the regex patch is narrow and well-contained, and the graceful-degradation warn path protects against upstream react-router changes.

The Vite plugin replaces a single throw with continue inside the react-router HMR loop, scoped entirely to apply: serve. The regex is carefully anchored to the exact error pattern, and the this.warn() fallback ensures nothing breaks silently if react-router changes its internal structure. The new integration test exercises the exact failure scenario end-to-end.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/compiler/templates.py Adds a post-enforce Vite plugin that patches the react-router HMR runtime regex at serve time; includes graceful warn fallback when the upstream pattern changes.
tests/integration/tests_playwright/test_hmr.py New integration test verifying unloaded-route edits no longer block subsequent loaded-route HMR updates; uses programmatically derived route IDs and a correct scan_pos cursor.
packages/reflex-base/news/6774.bugfix.md Changelog entry for the bugfix; one-line description, no issues.

Reviews (2): Last reviewed commit: "test(hmr): derive generated route paths ..." | Re-trigger Greptile

Comment thread tests/integration/tests_playwright/test_hmr.py Outdated
Comment thread tests/integration/tests_playwright/test_hmr.py
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.

1 participant