0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/packages/solid-router/src
Nico Lynzaad 22c9888857
fix(react-router, solid-router) - useParams should only be concerned about the relevant params (#5097)
#5020 highlighted an issue where when using useParams in parent route
(that has its own path param) with child routes that also use path
params this can cause excessive re-rendering of the parent route when
the params for the child routes changes.

The root cause for this is that the child params are available to the
parent route, even when strict=false was not specified and this also
does not match to the types that is being returned in this case. This
can be worked around by using select inside the useParams hook/function
but results in unnecessary boilerplate.

This PR attempts to resolve the issue by dealing with the two distinct
cases, one where we are only concerned about the path params of the
current route and prior routes (strict=true/undefined) and the second
where we want access in the parent route to the path params of the child
routes (strict=false).

In the strict case we use the match id to return the params of the
specific match, which is constant and results in stable rendering, while
in the strict=false case we fallback to the initial implementation of
returning params from the useMatch result which can be variable and
requires re-rendering to be done.

Changes were done on useParams for both react and solid, in solid's case
this wasn't causing re-renders but did return unexpected child params,
the change for solid is more toward keeping the API and expected outputs
consistent between the two frameworks. existing unit tests for react was
updated and e2e tests for both frameworks was added to ensure rendering
and results match the expected.

A separate merge has been prepared for Alpha and will be merged on
signoff of this one.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added nested named-parameter routes (three-level: foo → bar → baz) in
example apps with nested navigation, outlets, links and render-count
displays.
- Added a small render-counter component to visualize component
re-renders.

- **Bug Fixes**
- Improved params selection to respect strict vs non-strict modes,
reducing excess renders and producing stable param values.

- **Tests**
- Added E2E tests for React and Solid examples covering param navigation
and render-counts; expanded router unit tests for nested-route stability
and remount behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
History 2025-09-07 11:35:09 +02:00
..
ssr fefactor: restructure SSR handling between start/router (#4495) 2025-06-26 22:14:57 +02:00
Asset.tsx fix(react-router, solid-router): make head function scripts load properly (#4323) 2025-06-18 22:03:06 +02:00
awaited.tsx fix(solid-router): use createResource and Show in Await (#3591) 2025-02-27 14:30:51 +01:00
CatchBoundary.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
ClientOnly.tsx fix: don't run router.load() when hydrating only SSRed matches (#4630) 2025-07-12 01:18:27 +02:00
fileRoute.ts feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
HeadContent.tsx refactor(router-core,react-router,solid-router): avoid copying arrays just to .reverse() them (#4980) 2025-08-17 18:30:59 +02:00
history.ts feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
index.tsx refactor(router-core): simplify defaultParseSearch & defaultStringifySearch (#4985) 2025-08-19 08:42:53 +02:00
lazyRouteComponent.tsx feat: ssr setting per route (#4565) 2025-07-05 14:35:14 +02:00
link.tsx fix(react-router, solid-router): reduce useNavigate reactivity on path changes (#5037) 2025-08-31 13:48:25 +02:00
Match.tsx refactor(router-core): skip loader and store update if nothing to await (#4926) 2025-08-15 16:41:41 +02:00
matchContext.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
Matches.tsx fix(solid-router): RouteProvider Wrap and Match InnerWrap support propagating context to their children (#5033) 2025-08-29 21:24:38 +02:00
not-found.tsx fix(router-core): change error type in ErrorComponentProps (#4691) 2025-07-20 07:33:04 +02:00
renderRouteNotFound.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
route.tsx fix(router-plugin): add support for boolean and null literals in code splitter (#4915) 2025-08-13 13:01:57 +12:00
router.ts fix(solid-router): correctly assign createLazyFileRoute on window (#4956) 2025-08-16 19:15:58 +02:00
routerContext.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
RouterProvider.tsx fix(solid-router): RouteProvider Wrap and Match InnerWrap support propagating context to their children (#5033) 2025-08-29 21:24:38 +02:00
SafeFragment.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
ScriptOnce.tsx fix: remove debug log (#4604) 2025-07-11 19:49:35 +02:00
Scripts.tsx feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
scroll-restoration.tsx fix: scroll to top with hash history (#4795) 2025-07-27 00:36:40 +02:00
ScrollRestoration.tsx fix: properly handle sessionStorage not being available for scroll restoration (#4186) 2025-05-16 19:03:16 +02:00
Transitioner.tsx fix(solid-router): prevent client effects running on server (#4621) 2025-07-15 22:19:37 +02:00
typePrimitives.ts fix(router-core): move typePrimitives to shared package (#3748) 2025-03-12 13:30:19 +01:00
useBlocker.tsx fix: do not pre-decodeURI before passing to createMemoryHistory (#4893) 2025-08-08 15:36:37 -06:00
useCanGoBack.ts feat(solid-router): Add a SolidJS driver for TanStack Router (#3276) 2025-02-20 17:11:39 +01:00
useLoaderData.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useLoaderDeps.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useLocation.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useMatch.tsx fix(router-core): move ThrowConstraint to core utils (#3749) 2025-03-12 13:54:05 +01:00
useNavigate.tsx fix(react-router, solid-router): reduce useNavigate reactivity on path changes (#5037) 2025-08-31 13:48:25 +02:00
useParams.tsx fix(react-router, solid-router) - useParams should only be concerned about the relevant params (#5097) 2025-09-07 11:35:09 +02:00
useRouteContext.ts refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useRouter.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useRouterState.tsx refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00
useSearch.tsx fix(router-core): move ThrowConstraint to core utils (#3749) 2025-03-12 13:54:05 +01:00
utils.ts refactor(router-core): move AnyRoute and AnyRouter to router-core (#3640) 2025-03-04 21:48:58 +01:00