Repository navigation
fix(router-core): support parsed params in matchRoute - #7776
LadyBluenotes wants to merge 29 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
🚥 Pre-merge checks | ✅ 4 | ❌ 1
✨ Finishing Touches
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. Comment |
|
View your CI Pipeline Execution ↗ for commit 7404bb0
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview1 package(s) bumped directly, 22 bumped as dependents. 🟩 Patch bumps
|
…ck/router into match-route-parsed-params
Bundle Size Benchmarks
The following scenarios have bundle-size changes compared with the baseline:
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. |
Merging this PR will degrade performance by 0.29%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Sheraff
left a comment
There was a problem hiding this comment.
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.
Added a regression for |
|
@Sheraff made the changes we talked about in discord |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/router-core/src/new-process-route-tree.ts (2)
812-849: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff
findMatchalways redoes full extraction from scratch, discarding the incrementalextractstate already computed duringgetNodeMatch.When
includeRouteParamsis set, the constructedleafobject omitsextract(onlynode,skipped,rawParamsare carried over), forcingextractParamsto restart frompartIndex/nodeIndex/pathIndex/segmentCount = 0even though the winning frame may already have partially-resumedextractstate from earliervalidateParseParamscalls along the branch. This is correct but redundant for branches that use.parse(), doing O(n) extraction twice. Worth a look if this path is hot, though likely low priority given branch depth is typically small.🤖 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 `@packages/router-core/src/new-process-route-tree.ts` around lines 812 - 849, Reuse the incremental extract state from getNodeMatch in findMatch instead of restarting extractParams from zero. Preserve the winning leaf frame’s extract data when constructing or passing the leaf, and update extractParams to continue from that state while retaining existing rawParams and matchData behavior.
688-696: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
RouteMatchDatais defined but not reused for the identical inline shapes.The new
RouteMatchDatatype (line 858-862) exactly matches thematchDataelement shape that's independently inlined three more times:RouteMatch<T>.matchData(692-696),findMatch's return type (820-824), andextractParams's return tuple (885-889). Consolidating onto the shared alias avoids the four copies drifting apart if the shape changes later.♻️ Proposed refactor
type RouteMatch<T extends Extract<RouteLike, { fullPath: string }>> = { route: T rawParams: Record<string, string> branch: ReadonlyArray<T> - matchData: ReadonlyArray<{ - rawParams?: Record<string, string> - pathnameEnd: number - caseSensitive: boolean - }> + matchData: ReadonlyArray<RouteMatchData> }): { route: T rawParams: Record<string, string> - matchData?: ReadonlyArray<{ - rawParams?: Record<string, string> - pathnameEnd: number - caseSensitive: boolean - }> + matchData?: ReadonlyArray<RouteMatchData> } | null {extractedParams: Record<string, string>, - matchData?: Array<{ - rawParams?: Record<string, string> - pathnameEnd: number - caseSensitive: boolean - }>, + matchData?: Array<RouteMatchData>, ] {(Note: TypeScript type aliases aren't order-sensitive, so
RouteMatchDatacan be referenced ahead of its declaration without issue.)Also applies to: 813-825, 858-863, 885-889
🤖 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 `@packages/router-core/src/new-process-route-tree.ts` around lines 688 - 696, Reuse the shared RouteMatchData alias for every matchData element type instead of repeating its inline shape. Update RouteMatch<T>.matchData, findMatch’s return type, and extractParams’ return tuple to reference RouteMatchData, while keeping the alias definition and existing type structure unchanged.
🤖 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-core/src/new-process-route-tree.ts`:
- Line 951: Update the one-line conditionals in the route-tree logic: wrap the
body of the `if (part)` statement around `pathIndex += part.length` and the body
of the `if (result === false)` statement around `return null` in curly braces,
preserving their existing behavior.
---
Nitpick comments:
In `@packages/router-core/src/new-process-route-tree.ts`:
- Around line 812-849: Reuse the incremental extract state from getNodeMatch in
findMatch instead of restarting extractParams from zero. Preserve the winning
leaf frame’s extract data when constructing or passing the leaf, and update
extractParams to continue from that state while retaining existing rawParams and
matchData behavior.
- Around line 688-696: Reuse the shared RouteMatchData alias for every matchData
element type instead of repeating its inline shape. Update
RouteMatch<T>.matchData, findMatch’s return type, and extractParams’ return
tuple to reference RouteMatchData, while keeping the alias definition and
existing type structure unchanged.
🪄 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: af4b87d9-0cd5-46e6-9821-c5369b926b71
📒 Files selected for processing (7)
packages/router-core/src/new-process-route-tree.tspackages/router-core/src/router.tspackages/router-core/tests/match-by-path.test.tspackages/router-core/tests/match-route.test.tspackages/router-core/tests/optional-path-params-clean.test.tspackages/router-core/tests/optional-path-params.test.tspackages/router-core/tests/path.test.ts
💤 Files with no reviewable changes (1)
- packages/router-core/tests/match-by-path.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/router-core/src/router.ts
Reuse the path matcher for case-sensitive and fuzzy checks, including repeated parameter names and root paths. Consolidate parameter decoding and only collect per-route data when needed.
|
Can you remind me why we still need the |
|
does this collide with https://github.com/TanStack/router/pull/8327/changes? |
there's conflicts in files, if that's what youre referring to. I can stack this on manuel's? |
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Re-applies parsed-param matchRoute support on top of main's rewritten route matcher (#8327): findRouteMatch now records per-route raw params and path boundaries, matchRoute reuses the active matches, and params.parse gates see parsed ancestor params.
There was a problem hiding this comment.
Nx Cloud has identified a flaky task in your failed CI:
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
🎓 Learn more about Self-Healing CI on nx.dev
🦋 Changeset detectedLatest commit: 7404bb0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
matchRoutenow resolves matches through the processed route tree.params.parseresults before comparing or returning params.findSingleMatchand its cache withfindRouteMatch.caseSensitive, basepath, search, pending, optional-param, and wildcard behavior covered.matchRoutenow returnsfalsefor destination templates that are not registered in the route tree.Includes the reproducer from #2460.
Closes #2450.
Summary by CodeRabbit
params.parse/params.stringify, including proper numeric conversions.matchRoutenow returns parsed parameters (not raw strings) and correctly fails when typed parsing is rejected or throws.searchand trailing-slash behavior.matchRouteanduseMatchRoutetest coverage for React, Solid, and Vue, covering typed params, fuzzy matching, and mismatch cases.