fix(router-core): keep match.pathname consistent across nested matches with param parsing#7747
Conversation
…s with params.parse A route's params.parse result was written back into the shared routeParams object used to interpolate match.pathname for every route in the match chain, so a parent route's parsed param leaked into the pathname of routes matched after it. Keep routeParams raw for pathname interpolation and accumulate parsed params separately for match.params.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughModifies router-core route matching to propagate parsed ancestor parameters separately from raw route parameters, keeping nested ChangesStrict Param Propagation Fix
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant RouteMatcher
participant StrictParams
participant NestedMatch
RouteMatcher->>StrictParams: Accumulate parsed ancestor parameters
RouteMatcher->>NestedMatch: Set params from accumulated values
NestedMatch-->>RouteMatcher: Preserve raw pathname segments
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
match.pathnameis inconsistent across nested matches whenparams.parse/params.stringifyare used: a parent route keeps the raw value in its own pathname, but its parsed value leaks into child routes' pathnames.In
matchRoutesInternal(packages/router-core/src/router.ts), each match's pathname is built withinterpolatePathfrom a single sharedrouteParamsobject. After building a route's pathname,Object.assign(routeParams, strictParams)wrote that route'sparams.parseresult back into the same shared object, which is then used to interpolate the child routes' pathnames.This keeps
routeParamsraw for allinterpolatePathcalls and accumulates parsed params separately (accumulatedStrictParams), used only formatch.params. Parsed-param inheritance semantics are preserved.Added a
match-params.test.tscase asserting pathname consistency across nested matches with parse/stringify. It fails without the fix and passes with it. router-core plus the react/solid/vue router downstream suites pass, tsc clean.Closes #7731
Summary by CodeRabbit
Bug Fixes
match.pathnamestays aligned with the original URL segments.params.parse/params.stringify.Tests
params.parse/params.stringify.