0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/e2e/react-router/basic-file-based
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
..
src fix(react-router, solid-router) - useParams should only be concerned about the relevant params (#5097) 2025-09-07 11:35:09 +02:00
tests fix(react-router, solid-router) - useParams should only be concerned about the relevant params (#5097) 2025-09-07 11:35:09 +02:00
.gitignore chore(e2e): move hash related test utils to the shared package (#3782) 2025-03-16 14:24:39 +13:00
index.html test(react-router) should update title on navigation (#3610) 2025-03-02 22:56:22 +01:00
package.json fix: assign random ports for e2e tests (#4676) 2025-07-17 07:24:59 +02:00
playwright.config.ts test(e2e): use locally hosted api over an external provider (#4725) 2025-07-22 00:15:28 +02:00
postcss.config.mjs chore(e2e,examples): downgrade to tailwindcss 3 (#3249) 2025-01-27 13:28:27 +13:00
tailwind.config.mjs chore(e2e,examples): downgrade to tailwindcss 3 (#3249) 2025-01-27 13:28:27 +13:00
tsconfig.json test(e2e): use locally hosted api over an external provider (#4725) 2025-07-22 00:15:28 +02:00
vite.config.js feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00