fix(router-core): parse _strictParams. #5120
main fromrefs/pull/5120/head·merged by nlynzaad(GitHub profile, opens in a new tab) with changing useParams to make use of _strictParams it became apparent that _strictParams did not apply param parsing correctly. This PR resolves that problem and hence useParams now return the parsed params correctly.
This PR also adds unit tests in both react-router and solid-router to test this expected result.
A separate PR has been created to merge into alpha (#5121)
Summary by CodeRabbit#
New Features
- Stricter route parameter parsing and validation with support for custom parse/stringify.
- Clearer per-route parameter error reporting, with optional throw-on-error behavior.
- More consistent parameter values across nested routes and loaders.
Tests
- Added integration tests validating useParams with nested routing, custom param parsing/stringifying, and loader data in both React and Solid routers.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
View your CI Pipeline Execution ↗ for commit 2b966b1ed82c93259ee6d49894fe7dd56092619c
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded <1s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2s View ↗
☁️ Nx Cloud last updated this comment at
2025-09-11 07:24:34UTCMore 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-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-start-example-basic-react-query
- tanstack-start-example-basic-rsc
- tanstack-start-example-basic-static
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-example-large
- tanstack-start-example-material-ui
- 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-basic
- 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-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5120@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5120@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5120@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5120@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5120@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5120@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5120@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5120@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5120@tanstack/react-start-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@5120@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5120@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5120@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5120@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5120@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5120@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5120@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5120@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5120@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5120@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5120@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5120@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5120@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5120@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5120@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5120@tanstack/solid-start-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@5120@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5120@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5120@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5120@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5120@tanstack/start-server-functions-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@5120@tanstack/start-server-functions-fetcher
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@5120@tanstack/start-server-functions-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@5120@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5120@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5120@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5120@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5120commit:
2b966b1Actionable comments posted: 0
🧹 Nitpick comments (6)
packages/solid-router/tests/useParams.test.tsx (2)
181-191: Avoid wrapping router.load() and clicks in waitFor (can cause repeated side effects).Call router.load() once and click directly; wait on subsequent UI assertions instead.
- await waitFor(() => router.load()) + await router.load() ... - await waitFor(() => fireEvent.click(firstCategoryLink)) + fireEvent.click(firstCategoryLink) ... - await waitFor(() => fireEvent.click(allCategoryLink)) + fireEvent.click(allCategoryLink) ... - await waitFor(() => fireEvent.click(secondPostLink)) + fireEvent.click(secondPostLink)Also applies to: 225-235
210-214: Guard against null textContent and specify radix in parseInt.Prevents TS nullability complaints and ensures base-10 parsing.
- let renderedPost = { - id: parseInt(postIdValue.textContent), + let renderedPost = { + id: parseInt(postIdValue.textContent!, 10), title: postTitleValue.textContent, category: postCategory.textContent, } ... - renderedPost = { - id: parseInt(postIdValue.textContent), + renderedPost = { + id: parseInt(postIdValue.textContent!, 10), title: postTitleValue.textContent, category: postCategory.textContent, }Also applies to: 246-251
packages/router-core/src/router.ts (2)
1213-1218: Parse-cache missed on fullPath interpolation.interpolatePath supports parseCache; passing it avoids re-parsing templates across navigations.
- const { interpolatedPath } = interpolatePath({ + const { interpolatedPath } = interpolatePath({ path: route.fullPath, params: routeParams, decodeCharMap: this.pathParamsDecodeCharMap, + parseCache: this.parsePathnameCache, })
1227-1250: Strict per-route param parsing looks good; minor robustness tweak optional.If a parse function returns undefined/null, Object.assign will no-op but reads cleaner guarding the result.
- try { - Object.assign(strictParams, strictParseParams(strictParams as any)) + try { + const parsed = strictParseParams(strictParams as any) + if (parsed) Object.assign(strictParams, parsed)packages/react-router/tests/useParams.test.tsx (2)
182-199: Simplify act usage and avoid wrapping fireEvent with act.react-testing-library already wraps fireEvent in act. Use a single awaited act for router.load and click directly for events.
- await act(() => router.load()) + await act(async () => { await router.load() }) ... - await act(() => fireEvent.click(firstCategoryLink)) + fireEvent.click(firstCategoryLink) ... - await act(() => fireEvent.click(all-category-link)) + fireEvent.click(allCategoryLink) ... - await act(() => fireEvent.click(secondPostLink)) + fireEvent.click(secondPostLink)Also applies to: 226-236
210-215: Specify radix and guard null when parsing textContent.Avoids subtle parse issues and TS nullability warnings.
- let renderedPost = { - id: parseInt(postIdValue.textContent), + let renderedPost = { + id: parseInt(postIdValue.textContent!, 10), title: postTitleValue.textContent, category: postCategory.textContent, } ... - renderedPost = { - id: parseInt(postIdValue.textContent), + renderedPost = { + id: parseInt(postIdValue.textContent!, 10), title: postTitleValue.textContent, category: postCategory.textContent, }Also applies to: 247-252
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 6167c0c60d051a12a8256b75e01c1a288c6b3787 and b5d3686e947fe477a62fdab843a5c18159058bba.
📒 Files selected for processing (3)
packages/react-router/tests/useParams.test.tsx(1 hunks)packages/router-core/src/router.ts(4 hunks)packages/solid-router/tests/useParams.test.tsx(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/router-core/src/router.ts (1)
packages/router-core/src/path.ts (1)
interpolatePath(371-485)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (4)
packages/solid-router/tests/useParams.test.tsx (1)
138-149: Using useParams({ from: postRoute.fullPath }) here is correct and exercises strict parsing.This ensures leaf-route scoped parsed params are read. Nice.
packages/router-core/src/router.ts (2)
1219-1226: Verify matchId stability with route.id-based interpolation.Switching matchId to interpolatePath(route.id, { leaveWildcards: true }) changes the identity key. Please confirm no collisions for routes with optional/wildcard segments (e.g., siblings differing only by optional params) and that cache hits remain correct across param changes.
Would you run a quick check in your suite to ensure identical URLs across reloads resolve to the same match.id and that toggling optional params yields distinct match ids where expected?
Also applies to: 1258-1259
1274-1282: Correctly plumbs _strictParams and paramsError into matches.This aligns the match object with strict parsing semantics and per-route error surfacing.
Also applies to: 1299-1311
packages/react-router/tests/useParams.test.tsx (1)
139-170: LGTM: useParams is scoped to postRoute ensuring parsed values are asserted.Good coverage of category mapping and numeric id parsing, consistent with stringify handlers.
nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Introduces strict per-route parameter parsing and error handling in router-core, updates match construction to use strictly parsed params, and adds new integration tests for useParams in React and Solid routers validating nested params parsing/stringifying and loader data interactions.
Changes#
packages/router-core/src/router.tsroute.idinterpolation; applies per-routeparseto params with error capture/throw; updatesmatchId,_strictParams, and per-matchparamsError; keeps pathname fromroute.fullPath.packages/react-router/tests/useParams.test.tsxuseParams({ from: postRoute.fullPath }); verifies navigation and param/loader consistency.packages/solid-router/tests/useParams.test.tsxuseParamsbehavior across navigations.Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs#
useParamsselection ofmatch._strictParams, directly connected to these core changes and tests.Suggested labels#
package: react-router,package: router-core,package: solid-routerSuggested reviewers#
Poem#
Tip
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information.
Example:
Please share your feedback with us on this Discord post.
Pre-merge checks (2 passed, 1 warning)#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment `@coderabbitai help` to get the list of available commands and usage tips.