Skip to content
Source
Sign inSign up
TanStack/router

fix(router-plugin): only patch the route a module exported during route HMR #8686

OpenVugarAhmadov(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8686/headopened

Showing 16 changed files with 25 additions and 7 deletions (loading 13).

x
0 of 16 viewed, 16 left
5 additions and 0 deletions.changeset/route-hmr-own-route-only.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/router-plugin': patch
+---
+​
+Only let route HMR patch the route that the module itself exported. Matching by route id alone meant a route module from another app on the page, such as a Module Federation remote whose `__root__` or `/` shares an id with the host's, patched the host's route as soon as it loaded.
12 additions and 6 deletionspackages/router-plugin/src/core/hmr/vite-adapter.tsModified
View file
@@ -22,6 +22,10 @@
const routeIdFallback =
typeof opts.routeId === 'string' ? JSON.stringify(opts.routeId) : 'Route.id'
​
+ // The router holds the `Route` this module exported first, so only that
+ // route may be patched. Matching by id alone would also patch a route from
+ // another module, e.g. a Module Federation remote whose `__root__` or `/`
+ // shares an id with the host's.
return [
template.statement(
@@ -29,15 +33,15 @@
const hot = import.meta.hot
const hotData = hot.data ??= {}
const handleRouteUpdate = ${handleRouteUpdateCode}