router icon indicating copy to clipboard operation
router copied to clipboard

Top-Level Optional Route Parameter Breaks HMR in Network Mode

Open djobbo opened this issue 1 month ago • 1 comments

Which project does this relate to?

Router

Describe the bug

When using a top-level optional route parameter (e.g., /{-$locale}/), Vite HMR requests (like /@react-refresh) are incorrectly matched by the route in development mode when accessed via network IP instead of localhost. This breaks HMR when developing on non-localhost addresses.

Your Example Website or App

https://github.com/djobbo/tanstack-start-top-level-optional-route-param-repro

Steps to Reproduce the Bug or Issue

  1. Install dependencies:

    bun install
    
  2. Start dev server with network access:

    bun dev
    

    This runs: vite dev --host --port 3000

    The server will be accessible at both:

    • http://localhost:3000
    • http://[YOUR_IP]:3000 (e.g., http://192.168.1.100:3000)
  3. Test localhost (working):

    • Navigate to http://localhost:3000/en
    • Open server console
    • Observe: Only one log: locale: en
  4. Test network IP (broken):

    • Navigate to http://192.168.1.100:3000/en (use your actual IP)
    • Open server console
    • Observe: Multiple logs including locale: @react-refresh
    • HMR will not work

Expected behavior

  • Special Vite dev server paths (e.g., /@react-refresh, etc.) should not be matched by the route.
  • HMR should work consistently regardless of whether the app is accessed via localhost or network IP

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.132.0
  • OS: macOs & Linux (Debian 12)
  • Browser: Chrome
  • Browser Version: 142.0.7444.135
  • Bundler: vite
  • Bundler Version: 7.2.4

Additional context

I'm using top-level optional route parameters for i18n where routes like /, /en, /fr, etc. all need to work. This issue makes network development (testing on other devices or remote environment) impractical.

djobbo avatar Nov 22 '25 12:11 djobbo

this has nothing to do with optional path params, this is caused by the nitro vite plugin in dev commenting out the nitro vite plugin makes it work

cc @pi0

schiller-manuel avatar Nov 23 '25 10:11 schiller-manuel

please create an issue at https://github.com/nitrojs/nitro/issues

schiller-manuel avatar Dec 20 '25 21:12 schiller-manuel

should be fixed in latest nightly

pi0 avatar Dec 22 '25 09:12 pi0