Skip to content

fix(router-plugin): preserve HMR state for lowercase split components#7855

Merged
schiller-manuel merged 2 commits into
mainfrom
fix-7737
Jul 19, 2026
Merged

fix(router-plugin): preserve HMR state for lowercase split components#7855
schiller-manuel merged 2 commits into
mainfrom
fix-7737

Conversation

@schiller-manuel

@schiller-manuel schiller-manuel commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

fixes #7737

Summary by CodeRabbit

  • New Features
    • Improved React development HMR to preserve component state when route components use lowercase function names, including split route components and root shell, pending, and error components.
    • Added an e2e “lowercase named split” route to validate the behavior.
  • Bug Fixes
    • Development HMR behavior is enhanced while production output remains unchanged.
  • Tests
    • Expanded Playwright and snapshot coverage for lowercase-name HMR scenarios, including state preservation and expected UI/marker updates.

@nx-cloud

nx-cloud Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit efe5206

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 3m 42s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 28s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-19 10:05:10 UTC

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f251489-2a1d-4d5c-9edf-78e15dddb7cd

📥 Commits

Reviewing files that changed from the base of the PR and between efe5206 and f4e1f47.

📒 Files selected for processing (1)
  • packages/router-plugin/tests/router-plugin-context.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-plugin/tests/router-plugin-context.test.ts

📝 Walkthrough

Walkthrough

Changes

The router plugin now transforms lowercase React route component bindings for Fast Refresh across regular and code-split routes. Compiler plugin hooks and production detection were updated, with unit, snapshot, and end-to-end tests covering generated output, HMR updates, and state preservation.

Lowercase component HMR

Layer / File(s) Summary
Compiler plugin contracts and selection
packages/router-plugin/src/core/code-splitter/*, packages/router-plugin/src/core/config.ts, packages/router-plugin/src/index.ts
Adds virtual split-node compiler hooks, unifies compiler plugin types, and replaces reference-route HMR plugin selection with framework HMR plugin selection.
React refresh transformation pipeline
packages/router-plugin/src/core/code-splitter/plugins/react-refresh-route-components.ts, packages/router-plugin/src/core/router-code-splitter-plugin.ts, packages/router-plugin/src/core/router-hmr-plugin.ts
Renames lowercase route component bindings, hoists eligible components, and passes HMR plugins through reference and virtual route compilation.
Compiler and production-mode validation
packages/router-plugin/tests/add-hmr.test.ts, packages/router-plugin/tests/code-splitter.test.ts, packages/router-plugin/tests/router-plugin-context.test.ts, packages/router-plugin/tests/code-splitter/**
Tests HMR plugin wiring, lowercase split-component output, unchanged non-HMR output, and production-mode behavior.
Runtime HMR fixtures and end-to-end coverage
packages/router-plugin/tests/add-hmr/**, e2e/react-start/hmr/**, .changeset/fresh-routes-refresh.md
Adds root and split lowercase-component fixtures, browser tests for marker updates and state preservation, a generated test route, and a patch changeset.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RouteModule
  participant RouterCodeSplitter
  participant ReactRefreshPlugin
  participant ReactRuntime
  RouteModule->>RouterCodeSplitter: compile route and split components
  RouterCodeSplitter->>ReactRefreshPlugin: process route options and split nodes
  ReactRefreshPlugin->>RouterCodeSplitter: emit refresh-safe component bindings
  RouterCodeSplitter->>ReactRuntime: deliver updated HMR module
  ReactRuntime->>ReactRuntime: preserve component state and render updates
Loading

Possibly related PRs

  • TanStack/router#7000: Related React Fast Refresh and auto code-split route component handling in the router plugin.

Suggested reviewers: sheraff

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing HMR state preservation for lowercase split components.
Linked Issues check ✅ Passed The changes address #7737 by fixing lowercase route component Fast Refresh/HMR behavior, including root and shell component cases.
Out of Scope Changes check ✅ Passed The added refactors, tests, snapshots, and changeset all support the HMR lowercase-component fix and stay within scope.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-7737

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 6 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-plugin 1.168.22 → 1.168.23 Changeset
@tanstack/react-start 1.168.31 → 1.168.32 Dependent
@tanstack/react-start-rsc 0.1.30 → 0.1.31 Dependent
@tanstack/router-vite-plugin 1.167.22 → 1.167.23 Dependent
@tanstack/solid-start 1.168.31 → 1.168.32 Dependent
@tanstack/start-plugin-core 1.171.23 → 1.171.24 Dependent
@tanstack/vue-start 1.168.30 → 1.168.31 Dependent

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 30d2c3b85355
  • Measured at: 2026-07-19T10:01:48.219Z
  • Baseline source: history:218eab2c3bc6
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.35 KiB 0 B (0.00%) 87.21 KiB 273.70 KiB 76.01 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-router.full 91.06 KiB 0 B (0.00%) 90.92 KiB 285.59 KiB 79.19 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-router.minimal 35.53 KiB 0 B (0.00%) 35.40 KiB 105.90 KiB 31.94 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-router.full 40.58 KiB 0 B (0.00%) 40.46 KiB 121.11 KiB 36.51 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-router.minimal 53.00 KiB 0 B (0.00%) 52.87 KiB 149.94 KiB 47.63 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-router.full 58.94 KiB 0 B (0.00%) 58.81 KiB 168.70 KiB 52.76 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.minimal 101.99 KiB 0 B (0.00%) 101.85 KiB 322.13 KiB 88.23 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.deferred-hydration 102.72 KiB 0 B (0.00%) 101.87 KiB 323.50 KiB 88.88 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.full 105.36 KiB 0 B (0.00%) 105.23 KiB 332.06 KiB 91.12 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.rsbuild.minimal 99.68 KiB 0 B (0.00%) 99.51 KiB 316.57 KiB 85.74 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.rsbuild.minimal-iife 100.08 KiB 0 B (0.00%) 99.91 KiB 317.51 KiB 86.11 KiB ▅▅▅▅▅▅▅▅▅▅▅
react-start.rsbuild.full 102.89 KiB 0 B (0.00%) 102.72 KiB 326.63 KiB 88.52 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-start.minimal 49.61 KiB 0 B (0.00%) 49.48 KiB 152.07 KiB 43.83 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-start.deferred-hydration 52.87 KiB 0 B (0.00%) 49.53 KiB 160.11 KiB 46.89 KiB ▅▅▅▅▅▅▅▅▅▅▅
solid-start.full 55.42 KiB 0 B (0.00%) 55.29 KiB 169.12 KiB 48.90 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-start.minimal 71.03 KiB 0 B (0.00%) 70.90 KiB 207.19 KiB 62.89 KiB ▅▅▅▅▅▅▅▅▅▅▅
vue-start.full 75.03 KiB 0 B (0.00%) 74.90 KiB 219.83 KiB 66.37 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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7855

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7855

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7855

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7855

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7855

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7855

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7855

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7855

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7855

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7855

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7855

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7855

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7855

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7855

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7855

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7855

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7855

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7855

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7855

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7855

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7855

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7855

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7855

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7855

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7855

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7855

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7855

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7855

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7855

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7855

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7855

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7855

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7855

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7855

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7855

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7855

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7855

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7855

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7855

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7855

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7855

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7855

commit: f4e1f47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable 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 `@packages/router-plugin/tests/router-plugin-context.test.ts`:
- Line 126: Stub process.env.NODE_ENV to "production" before creating the
production plugin in the createRouterCodeSplitterPlugin test setup, and restore
the original environment value in a finally block. Keep the non-production test
behavior unchanged and ensure the stub covers plugin factory creation, not
merely configurePlugin.
🪄 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: 6965db7f-a636-4a53-a039-d037bc6b2686

📥 Commits

Reviewing files that changed from the base of the PR and between 218eab2 and efe5206.

📒 Files selected for processing (36)
  • .changeset/fresh-routes-refresh.md
  • e2e/react-start/hmr/src/routeTree.gen.ts
  • e2e/react-start/hmr/src/routes/__root.tsx
  • e2e/react-start/hmr/src/routes/component-hmr-lowercase-named-split.tsx
  • e2e/react-start/hmr/tests/app.spec.ts
  • packages/router-plugin/src/core/code-splitter/compilers.ts
  • packages/router-plugin/src/core/code-splitter/plugins.ts
  • packages/router-plugin/src/core/code-splitter/plugins/framework-plugins.ts
  • packages/router-plugin/src/core/code-splitter/plugins/react-refresh-route-components.ts
  • packages/router-plugin/src/core/config.ts
  • packages/router-plugin/src/core/router-code-splitter-plugin.ts
  • packages/router-plugin/src/core/router-hmr-plugin.ts
  • packages/router-plugin/src/index.ts
  • packages/router-plugin/tests/add-hmr.test.ts
  • packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@false.tsx
  • packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@true.tsx
  • packages/router-plugin/tests/add-hmr/snapshots/react/createRootRoute-lowercase-components@false.tsx
  • packages/router-plugin/tests/add-hmr/snapshots/react/createRootRoute-lowercase-components@true.tsx
  • packages/router-plugin/tests/add-hmr/test-files/react/createFileRoute-lowercase-components.tsx
  • packages/router-plugin/tests/add-hmr/test-files/react/createRootRoute-lowercase-components.tsx
  • packages/router-plugin/tests/code-splitter.test.ts
  • packages/router-plugin/tests/code-splitter/snapshots/react/1-default/lowercase-function-declaration.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/1-default/lowercase-function-declaration@component.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/1-default/lowercase-function-declaration@errorComponent.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/1-default/lowercase-function-declaration@notFoundComponent.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/1-default/lowercase-function-declaration@shared.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/lowercase-function-declaration.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/lowercase-function-declaration@component---errorComponent---notFoundComponent---pendingComponent.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/lowercase-function-declaration@loader.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/lowercase-function-declaration@shared.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/lowercase-function-declaration.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/lowercase-function-declaration@component---loader---notFoundComponent---pendingComponent.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/lowercase-function-declaration@errorComponent.tsx
  • packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/lowercase-function-declaration@shared.tsx
  • packages/router-plugin/tests/code-splitter/test-files/react/lowercase-function-declaration.tsx
  • packages/router-plugin/tests/router-plugin-context.test.ts

Comment thread packages/router-plugin/tests/router-plugin-context.test.ts Outdated
@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.01%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 176 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server serialization-payload (react) 3.4 MB 5.2 MB -33.82%
Memory mem server error-paths not-found (solid) 616.4 KB 813.6 KB -24.24%
Memory mem server streaming-peak chunked (vue) 11.1 MB 13.4 MB -17.19%
Memory mem server request-churn (react) 530.9 KB 487.7 KB +8.85%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix-7737 (f4e1f47) with main (218eab2)

Open in CodSpeed

@schiller-manuel
schiller-manuel merged commit 49f6863 into main Jul 19, 2026
25 checks passed
@schiller-manuel
schiller-manuel deleted the fix-7737 branch July 19, 2026 10:09
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lowercase named route component silently fails Fast Refresh with auto code splitting

1 participant