fix(router-plugin): preserve generated route state for aliased HMR imports #7560
main fromrefs/pull/7560/head·merged by schiller-manuel(GitHub profile, opens in a new tab) fixes #4303
Summary by CodeRabbit#
Bug Fixes
- Fixed route HMR behavior to preserve generated route properties when using aliased route imports, ensuring hot reloads maintain route identity, parent relationships, and path information.
Tests
- Added E2E tests for aliased route import hot module reloading.
- Added unit tests for route export synchronization during HMR updates.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-plugin
View your CI Pipeline Execution ↗ for commit 7cb2f05abb0aecb85a269d71faf513908cd1cc31
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 9m 38s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 12s View ↗ 💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at
2026-06-06 08:32:40UTC🚀 Changeset Version Preview#
1 package(s) bumped directly, 6 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/router-plugin1.168.16 → 1.168.17 Changeset @tanstack/react-start1.168.22 → 1.168.23 Dependent @tanstack/react-start-rsc0.1.21 → 0.1.22 Dependent @tanstack/router-vite-plugin1.167.16 → 1.167.17 Dependent @tanstack/solid-start1.168.22 → 1.168.23 Dependent @tanstack/start-plugin-core1.171.14 → 1.171.15 Dependent @tanstack/vue-start1.168.21 → 1.168.22 Dependent Bundle Size Benchmarks#
- Commit:
ab9632209474 - Measured at:
2026-06-06T08:24:04.349Z - Baseline source:
history:e99e855258e3 - Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend react-router.minimal87.24 KiB 0 B (0.00%) 87.10 KiB 273.72 KiB 75.94 KiB █▁▁▁▁▁▁▁▆▆▆ react-router.full91.02 KiB 0 B (0.00%) 90.88 KiB 286.03 KiB 79.16 KiB ▂▁▁▁▁▁▁▁███ solid-router.minimal35.47 KiB 0 B (0.00%) 35.34 KiB 106.02 KiB 31.96 KiB █▁▁▁▁▁▁▁▇▇▇ solid-router.full40.50 KiB 0 B (0.00%) 40.38 KiB 121.16 KiB 36.44 KiB ▂▁▁▁▁▁▁▁███ vue-router.minimal52.95 KiB 0 B (0.00%) 52.82 KiB 150.04 KiB 47.63 KiB █▁▁▁▁▁▁▁▅▅▅ vue-router.full58.93 KiB 0 B (0.00%) 58.80 KiB 168.72 KiB 52.76 KiB ▂▁▁▁▁▁▁▁███ react-start.minimal101.86 KiB 0 B (0.00%) 101.72 KiB 322.04 KiB 88.18 KiB █▁▁▁▁▁▁▁▆▆▆ react-start.deferred-hydration102.60 KiB 0 B (0.00%) 101.75 KiB 323.42 KiB 88.78 KiB █▁▁▁▁▁▁▁▇▇▇ react-start.full105.25 KiB 0 B (0.00%) 105.11 KiB 332.35 KiB 91.09 KiB █▁▁▁▁▁▁▁▇▇▇ react-start.rsbuild.minimal99.57 KiB 0 B (0.00%) 99.40 KiB 316.51 KiB 85.66 KiB █▁▁▁▁▁▁▁▆▆▆ react-start.rsbuild.minimal-iife99.97 KiB 0 B (0.00%) 99.80 KiB 317.45 KiB 85.94 KiB █▁▁▁▁▁▁▁▆▆▆ react-start.rsbuild.full102.83 KiB 0 B (0.00%) 102.66 KiB 326.91 KiB 88.33 KiB █▁▁▁▁▁▁▁▅▅▅ solid-start.minimal49.58 KiB 0 B (0.00%) 49.45 KiB 152.09 KiB 43.77 KiB █▁▁▁▁▁▁▁▇▇▇ solid-start.deferred-hydration52.84 KiB 0 B (0.00%) 49.50 KiB 160.13 KiB 46.76 KiB █▁▁▁▁▁▁▁▇▇▇ solid-start.full55.36 KiB 0 B (0.00%) 55.23 KiB 169.02 KiB 48.79 KiB █▁▁▁▁▁▁▁▆▆▆ vue-start.minimal70.99 KiB 0 B (0.00%) 70.87 KiB 207.18 KiB 62.87 KiB █▁▁▁▁▁▁▁▆▆▆ vue-start.full74.96 KiB 0 B (0.00%) 74.83 KiB 219.70 KiB 66.27 KiB █▁▁▁▁▁▁▁▆▆▆ Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.
- Commit:
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@7560@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7560@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7560@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@7560@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7560@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@7560@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@7560@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7560@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@7560@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@7560@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@7560@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@7560@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@7560@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@7560@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@7560@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@7560@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@7560@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@7560@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7560@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@7560@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7560@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@7560@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7560@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7560@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@7560@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@7560@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@7560@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@7560@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7560@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@7560@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@7560@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7560@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@7560@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@7560@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7560@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@7560@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7560@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7560@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@7560@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@7560@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@7560@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@7560commit:
83e7c8dActionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@e2e/react-start/hmr/tests/app.spec.ts`: - Around line 30-31: The new editable aliased route panels (aliasedRouteImportParentPanel and aliasedRouteImportChildPanel) lack entries in the routeFileRestoreChecks map so waitForRestoredRouteFile returns immediately; add routeFileRestoreChecks entries for both aliasedRouteImportParentPanel and aliasedRouteImportChildPanel that point to their component file paths (components/AliasedRouteImportParentPanel.tsx and components/AliasedRouteImportChildPanel.tsx) and provide appropriate content/match checks (the same style used by other entries) so waitForRestoredRouteFile blocks until HMR restore is observed.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
0e497855-910d-40d8-bc3f-c85aaf87f835📥 Commits
Reviewing files that changed from the base of the PR and between e99e855258e3350832b7b09a637af8f9d417f1b9 and 83e7c8d927152e4ba2698643c5610a2969e422ed.
📒 Files selected for processing (21)
.changeset/fix-route-hmr-aliased-imports.mde2e/react-start/hmr/src/components/AliasedRouteImportChildPanel.tsxe2e/react-start/hmr/src/components/AliasedRouteImportParentPanel.tsxe2e/react-start/hmr/src/routeTree.gen.tse2e/react-start/hmr/src/routes/aliased-route-imports.$id.child.tsxe2e/react-start/hmr/src/routes/aliased-route-imports.$id.tsxe2e/react-start/hmr/tests/app.spec.tspackages/router-plugin/src/core/hmr/handle-route-update.tspackages/router-plugin/src/core/hmr/vite-adapter.tspackages/router-plugin/tests/add-hmr.test.tspackages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@webpack-hot.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/createRootRoute-inline-component@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/createRootRoute@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/createRootRouteWithContext-type-args@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/explicit-undefined-component@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/function-declaration@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/multi-component@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/react/string-literal-keys@true.tsxpackages/router-plugin/tests/add-hmr/snapshots/solid/arrow-function@true.tsxpackages/router-plugin/tests/handle-route-update.test.ts
e2e/react-start/hmr/tests/app.spec.ts lines 30 to 31@@ -27,3 +27,5 @@2727 componentHmrNamedNosplit: 'routes/component-hmr-named-nosplit.tsx',2828 componentHmrInlineErrorSplit: 'routes/component-hmr-inline-error-split.tsx',2929 componentHmrNamedErrorSplit: 'routes/component-hmr-named-error-split.tsx',30+ aliasedRouteImportParentPanel: 'components/AliasedRouteImportParentPanel.tsx',31+ aliasedRouteImportChildPanel: 'components/AliasedRouteImportChildPanel.tsx',⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Add restore checks for the new aliased route panel files.
aliasedRouteImportParentPanelandaliasedRouteImportChildPanelare now editable/restored, but they have norouteFileRestoreChecksentries. That makeswaitForRestoredRouteFilereturn early for these keys, so subsequent tests can run before restore HMR settles.Suggested patch
const routeFileRestoreChecks: Partial< Record< RouteFileKey, { url: string testId: string text: string assert?: (page: Page) => Promise<void> } > > = { + aliasedRouteImportParentPanel: { + url: '/aliased-route-imports/A', + testId: 'aliased-parent-marker', + text: 'aliased-parent-baseline', + }, + aliasedRouteImportChildPanel: { + url: '/aliased-route-imports/A/child', + testId: 'aliased-child-marker', + text: 'aliased-child-baseline', + }, index: { url: '/', testId: 'marker', text: 'baseline',Also applies to: 229-236
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@e2e/react-start/hmr/tests/app.spec.ts` around lines 30 - 31, The new editable aliased route panels (aliasedRouteImportParentPanel and aliasedRouteImportChildPanel) lack entries in the routeFileRestoreChecks map so waitForRestoredRouteFile returns immediately; add routeFileRestoreChecks entries for both aliasedRouteImportParentPanel and aliasedRouteImportChildPanel that point to their component file paths (components/AliasedRouteImportParentPanel.tsx and components/AliasedRouteImportChildPanel.tsx) and provide appropriate content/match checks (the same style used by other entries) so waitForRestoredRouteFile blocks until HMR restore is observed.Merging this PR will not alter performance#
✅ 5untouched benchmarks⏩ 1skipped benchmark1
Comparingfix-4303(83e7c8d) withmain(e99e855)Footnotes#
-
1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩
-
Sign in to join this conversation.
Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes.
📝 Walkthrough
Walkthrough#
This PR fixes hot-reload behavior for TanStack Router routes imported via aliases. Route properties (
id,to,path,fullPath) are now synchronized from live routes to newly imported route exports during HMR, enabling aliased route imports to work correctly across hot reloads in both parent and child route components.Changes#
Router-plugin HMR aliased import fix
e2e/react-start/hmr/src/components/AliasedRouteImportChildPanel.tsx,e2e/react-start/hmr/src/components/AliasedRouteImportParentPanel.tsx,e2e/react-start/hmr/src/routes/aliased-route-imports.$id.tsx,e2e/react-start/hmr/src/routes/aliased-route-imports.$id.child.tsx,e2e/react-start/hmr/src/routeTree.gen.ts/aliased-route-imports/$idand child route. Generated route tree is updated with route imports, instances, type registries (FileRoutesByFullPath,FileRoutesByTo,FileRoutesById,FileRouteTypes,RootRouteChildren), and module augmentation for the new routes.packages/router-plugin/src/core/hmr/handle-route-update.tsAnyRouteWithPrivatePropstype withparentRoutefield. After rebuilding route tree,syncHotRouteExport(oldRoute)copies generated route state (options,parentRoute,_path,_id,_fullPath,_to) from the live route onto the freshly imported route export.packages/router-plugin/src/core/hmr/vite-adapter.ts,packages/router-plugin/tests/add-hmr/snapshots/react/*,packages/router-plugin/tests/add-hmr/snapshots/solid/*initialRouteIdinhot.data, reconciles against existing router state beforehot.accept(applyinghandleRouteUpdateif needed), and prevents duplicate patching viatsr-route-update-handledguard. Regenerated snapshots (React/Solid) refactorhandleRouteUpdateas a reusable shared function, add pre-accept route reconciliation, and applysyncHotRouteExportwithin the update flow.e2e/react-start/hmr/tests/app.spec.tspackages/router-plugin/tests/add-hmr.test.ts,packages/router-plugin/tests/handle-route-update.test.ts,.changeset/fix-route-hmr-aliased-imports.mdinitialRouteIdis included and uses nullish-coalescing fallback tohotData. Adds test coverage forhandleRouteUpdateroute property hydration, ensuringnewRouteis populated withid,path,fullPath,to,parentRoute, andoptionsfrom the live route. Changeset entry documents patch version bump for the HMR aliased-import fix.Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs#
packages/router-plugin/src/core/hmr/handle-route-update.tsHMR path/route-index reconciliation logic (preserving/syncing generated route identity/options and refreshing the route tree) to prevent route mismatches after hot updates.Suggested reviewers#
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#4303by synchronizing route state (id, path, fullPath, to, parentRoute, options) during HMR to preserve aliased import functionality.✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.