Skip to content
Source
Sign inSign up
TanStack/router

fix: HMR: only invalidate router if match is existing and not cached #5713

Mergedschiller-manuel(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/5713/headmerged by schiller-manuel(GitHub profile, opens in a new tab)

Showing 4 changed files with 20 additions and 8 deletions (loading 1).

x
0 of 4 viewed, 4 left
8 additions and 2 deletionspackages/router-plugin/src/core/route-hmr-statement.tsModified
View file
@@ -1,5 +1,5 @@
import * as template from '@babel/template'
-import type { AnyRoute } from '@tanstack/router-core'
+import type { AnyRoute, AnyRouteMatch } from '@tanstack/router-core'
​
type AnyRouteWithPrivateProps = AnyRoute & {
_path: string
@@ -26,7 +26,13 @@
if (oldRouteIndex > -1) {
router.flatRoutes[oldRouteIndex] = newRoute
- router.invalidate({ filter: (m) => m.routeId === oldRoute.id })
+ const filter = (m: AnyRouteMatch) => m.routeId === oldRoute.id
+ if (
+ router.state.matches.find(filter) ||
+ router.state.pendingMatches?.find(filter)
+ ) {
+ router.invalidate({ filter })
+ }
​
export const routeHmrStatement = template.statement(
6 additions and 3 deletionspackages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsxModified
View file