Skip to content

fix(router-core): support parsed params in matchRoute#7776

Open
LadyBluenotes wants to merge 6 commits into
mainfrom
match-route-parsed-params
Open

fix(router-core): support parsed params in matchRoute#7776
LadyBluenotes wants to merge 6 commits into
mainfrom
match-route-parsed-params

Conversation

@LadyBluenotes

@LadyBluenotes LadyBluenotes commented Jul 10, 2026

Copy link
Copy Markdown
Member

matchRoute now applies route parameter parsers before it compares or returns matched params. This restores matching for routes that use custom path parameter parsing, including typed params and parser-rejected values.

Adds regression coverage in router-core and the React, Solid, and Vue Matches tests.

Includes the reproducer from #2460.

Closes #2450.

Summary by CodeRabbit

  • Bug Fixes

    • Improved route matching for custom parsed path parameters.
    • Typed parameters are now correctly parsed and compared during route matching.
    • Invalid, rejected, or unparseable parameters safely return no match.
    • Matching now works consistently with nested routes, base paths, search parameters, and non-canonical slugs.
  • Tests

    • Added coverage across React, Solid, and Vue integrations.

@coderabbitai

coderabbitai Bot commented Jul 11, 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: 0cc0dc86-8f9b-4c52-89f1-fb21860cb357

📥 Commits

Reviewing files that changed from the base of the PR and between 22af4b8 and f396cca.

📒 Files selected for processing (2)
  • .changeset/plenty-jokes-listen.md
  • packages/router-core/tests/match-route.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/plenty-jokes-listen.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-core/tests/match-route.test.ts

📝 Walkthrough

Walkthrough

matchRoute now parses route parameters before matching and returns typed values. Core tests cover parser behavior and existing matching modes, while React, Solid, and Vue tests verify typed results from useMatchRoute.

Changes

Typed route matching

Layer / File(s) Summary
Parse parameters during route matching
packages/router-core/src/router.ts, .changeset/plenty-jokes-listen.md
matchRoute parses parameters across the destination route branch, rejects invalid parser results, compares parsed values, returns typed parameters, and records a patch release.
Validate core matchRoute behavior
packages/router-core/tests/match-route.test.ts
Tests cover typed values, parser failures, slug parsing, parent-child parsing, generic and fuzzy matching, search parameters, and base paths.
Verify typed useMatchRoute results
packages/react-router/tests/Matches.test.tsx, packages/solid-router/tests/Matches.test.tsx, packages/vue-router/tests/Matches.test.tsx
Adapter tests verify that useMatchRoute returns numeric parameters produced by custom route parsers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant useMatchRoute
  participant RouterCore.matchRoute
  participant RouteParser
  useMatchRoute->>RouterCore.matchRoute: Match route with typed params
  RouterCore.matchRoute->>RouteParser: Parse raw URL parameters
  RouteParser-->>RouterCore.matchRoute: Return parsed params or rejection
  RouterCore.matchRoute-->>useMatchRoute: Return typed match or false
Loading

Suggested reviewers: Sheraff, nlynzaad

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 states the core fix in router-core and matches the main change in matchRoute param handling.
Linked Issues check ✅ Passed The code updates matchRoute to apply custom param parsing before matching and adds regression tests for numeric parsed params, satisfying #2450.
Out of Scope Changes check ✅ Passed The added tests and changeset all support the parsed-param matchRoute fix and do not introduce unrelated 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 match-route-parsed-params

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@LadyBluenotes LadyBluenotes requested a review from Sheraff July 11, 2026 00:00
@nx-cloud

nx-cloud Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 22af4b8

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

☁️ Nx Cloud last updated this comment at 2026-07-11 00:21:26 UTC

@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

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

🟩 Patch bumps

Package Version Reason
@tanstack/router-core 1.171.14 → 1.171.15 Changeset
@tanstack/react-router 1.170.17 → 1.170.18 Dependent
@tanstack/react-start 1.168.27 → 1.168.28 Dependent
@tanstack/react-start-client 1.168.15 → 1.168.16 Dependent
@tanstack/react-start-rsc 0.1.26 → 0.1.27 Dependent
@tanstack/react-start-server 1.167.21 → 1.167.22 Dependent
@tanstack/router-cli 1.167.18 → 1.167.19 Dependent
@tanstack/router-generator 1.167.18 → 1.167.19 Dependent
@tanstack/router-plugin 1.168.19 → 1.168.20 Dependent
@tanstack/router-vite-plugin 1.167.19 → 1.167.20 Dependent
@tanstack/solid-router 1.170.17 → 1.170.18 Dependent
@tanstack/solid-start 1.168.27 → 1.168.28 Dependent
@tanstack/solid-start-client 1.168.15 → 1.168.16 Dependent
@tanstack/solid-start-server 1.167.21 → 1.167.22 Dependent
@tanstack/start-client-core 1.170.13 → 1.170.14 Dependent
@tanstack/start-plugin-core 1.171.19 → 1.171.20 Dependent
@tanstack/start-server-core 1.169.16 → 1.169.17 Dependent
@tanstack/start-static-server-functions 1.167.18 → 1.167.19 Dependent
@tanstack/start-storage-context 1.167.16 → 1.167.17 Dependent
@tanstack/vue-router 1.170.16 → 1.170.17 Dependent
@tanstack/vue-start 1.168.26 → 1.168.27 Dependent
@tanstack/vue-start-client 1.167.18 → 1.167.19 Dependent
@tanstack/vue-start-server 1.167.21 → 1.167.22 Dependent

@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: f396cca

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 29a8148be8be
  • Measured at: 2026-07-11T00:14:18.384Z
  • Baseline source: history:a3e24c35a58d
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.44 KiB +66 B (+0.07%) 87.30 KiB 274.13 KiB 76.13 KiB ▁▃▃▃▃▅▅▅▅▅▅█
react-router.full 91.17 KiB +72 B (+0.08%) 91.04 KiB 286.02 KiB 79.21 KiB ▁▃▃▃▃▅▅▅▅▅▅█
solid-router.minimal 35.63 KiB +65 B (+0.18%) 35.50 KiB 106.33 KiB 32.16 KiB ▁▃▃▃▃▅▅▅▅▅▅█
solid-router.full 40.68 KiB +71 B (+0.17%) 40.56 KiB 121.54 KiB 36.64 KiB ▁▃▃▃▃▅▅▅▅▅▅█
vue-router.minimal 53.12 KiB +58 B (+0.11%) 52.99 KiB 150.37 KiB 47.75 KiB ▁▃▃▃▃▅▅▅▅▅▅█
vue-router.full 59.09 KiB +63 B (+0.10%) 58.97 KiB 169.13 KiB 52.90 KiB ▁▃▃▃▃▅▅▅▅▅▅█
react-start.minimal 102.10 KiB +79 B (+0.08%) 101.97 KiB 322.56 KiB 88.28 KiB ▁▂▂▂▄▅▅▅▅▅▅█
react-start.deferred-hydration 102.84 KiB +83 B (+0.08%) 101.99 KiB 323.93 KiB 89.09 KiB ▁▂▂▂▄▅▅▅▅▅▅█
react-start.full 105.52 KiB +70 B (+0.06%) 105.38 KiB 332.49 KiB 91.22 KiB ▁▂▂▂▄▆▆▆▆▆▆█
react-start.rsbuild.minimal 99.79 KiB +54 B (+0.05%) 99.62 KiB 316.98 KiB 85.93 KiB ▁▃▂▂▄▆▆▆▆▆▆█
react-start.rsbuild.minimal-iife 100.20 KiB +54 B (+0.05%) 100.03 KiB 317.91 KiB 86.31 KiB ▁▂▂▂▄▆▆▆▆▆▆█
react-start.rsbuild.full 103.02 KiB +63 B (+0.06%) 102.85 KiB 327.03 KiB 88.66 KiB ▁▂▂▂▄▅▅▅▅▅▅█
solid-start.minimal 49.76 KiB +56 B (+0.11%) 49.63 KiB 152.50 KiB 44.00 KiB ▁▃▃▃▄▆▆▆▆▆▆█
solid-start.deferred-hydration 53.03 KiB +56 B (+0.10%) 49.69 KiB 160.54 KiB 46.94 KiB ▁▃▃▃▄▆▆▆▆▆▆█
solid-start.full 55.58 KiB +68 B (+0.12%) 55.45 KiB 169.55 KiB 48.97 KiB ▁▃▃▃▄▅▅▅▅▅▅█
vue-start.minimal 71.19 KiB +62 B (+0.09%) 71.06 KiB 207.62 KiB 63.10 KiB ▁▃▃▃▅▆▆▆▆▆▆█
vue-start.full 75.19 KiB +64 B (+0.08%) 75.06 KiB 220.26 KiB 66.57 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.

@codspeed-hq

codspeed-hq Bot commented Jul 11, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 31.13%

⚠️ 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

⚡ 3 improved benchmarks
❌ 5 regressed benchmarks
✅ 172 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server server-fn-churn (solid) 274 KB 3,551.7 KB -92.29%
Memory mem server serialization-payload (vue) 3.5 MB 6.4 MB -45.95%
Memory mem server error-paths not-found (solid) 427 KB 696.4 KB -38.69%
Memory mem server error-paths not-found (vue) 387.9 KB 467 KB -16.93%
Memory mem server peak-large-page (vue) 715.4 KB 760.8 KB -5.97%
Memory mem server error-paths unmatched (react) 606.9 KB 313.3 KB +93.68%
Memory mem server streaming-peak chunked (vue) 13.9 MB 11.1 MB +25.42%
Memory mem server server-fn-churn (react) 283 KB 271.3 KB +4.31%

Tip

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


Comparing match-route-parsed-params (f396cca) with main (a3e24c3)

Open in CodSpeed

@nx-cloud nx-cloud 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.

Nx Cloud is proposing a fix for your failed CI:

We extracted the anonymous component arrow function into a named InvoiceComponent function to fix the react-hooks/rules-of-hooks ESLint error. The rule requires React component functions to start with an uppercase letter, which the lowercase component property name did not satisfy. This change preserves the full test intent while making the hook usage compliant.

Warning

We could not verify this fix.

Suggested Fix changes
diff --git a/packages/react-router/tests/Matches.test.tsx b/packages/react-router/tests/Matches.test.tsx
index e756a567..996c9d03 100644
--- a/packages/react-router/tests/Matches.test.tsx
+++ b/packages/react-router/tests/Matches.test.tsx
@@ -147,6 +147,16 @@ test('should show pendingComponent of root route', async () => {
 
 test('useMatchRoute matches typed params from routes with custom parse and stringify functions', async () => {
   const rootRoute = createRootRoute()
+
+  function InvoiceComponent() {
+    const matchRoute = useMatchRoute()
+    const match = matchRoute({
+      to: '/invoices/$invoiceId',
+      params: { invoiceId: 123 },
+    })
+    return <div data-testid="match">{JSON.stringify(match)}</div>
+  }
+
   const invoiceRoute = createRoute({
     getParentRoute: () => rootRoute,
     path: '/invoices/$invoiceId',
@@ -158,15 +168,7 @@ test('useMatchRoute matches typed params from routes with custom parse and strin
         invoiceId: String(invoiceId),
       }),
     },
-    component: () => {
-      const matchRoute = useMatchRoute()
-      const match = matchRoute({
-        to: '/invoices/$invoiceId',
-        params: { invoiceId: 123 },
-      })
-
-      return <div data-testid="match">{JSON.stringify(match)}</div>
-    },
+    component: InvoiceComponent,
   })
   const router = createRouter({
     routeTree: rootRoute.addChildren([invoiceRoute]),

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally 9YYT-RTGB

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

@Sheraff Sheraff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it makes sense to fix this. But also router.matchRoute is broken more generally because it does not take the route tree into account. It could return true for the specific route you're asking for, but when actually compared against the entire tree, another route would match because it had higher matching priority.

Comment on lines +3003 to +3018
try {
for (const matchedRoute of this.getRouteBranch(destinationRoute)) {
const parseParams =
matchedRoute.options.params?.parse ??
matchedRoute.options.parseParams
if (parseParams) {
const parsedParams = parseParams(params as Record<string, string>)
if (parsedParams === false) {
return false
}
Object.assign(params, parsedParams)
}
}
} catch {
return false
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this could be shortened using the extractStrictParams method that exists in this file

      for (const matchedRoutes of this.getRouteBranch(destinationRoute)) {
        try {
          extractStrictParams(route, params)
        } catch {
          return false
        }
      }

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.

MatchRoute component fails with custom parse/stringify for numeric route params

2 participants