Describe the bug#
PR #2056 added key property to route component
https://github.com/TanStack/router/blob/06c3a6923dc71c9f2fbd6e999c3aa93817fa89d0/packages/react-router/src/Match.tsx#L139-L142
Due to this, route component is recreated, rather then reconciled, if matchId contains path params.
Your Example Website or App#
no example app
Steps to Reproduce the Bug or Issue#
When I have these routes:
view.$id.tsx
view.$id.index.tsx
view.$id.edit.tsx
And navigate from /view/one/ to /view/two
Expected behavior#
I expect route component of view.$id is not unmounted and mounted again, as due to this internal state is not preserved
Screenshots or Videos#
No response
Platform#
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context#
No response
This was part of a perf improvement done to stop the numerous rerenders happening because people didn't memorize their components. Whilst this change certainly had the intended effect of reducing the number of times a component was rendering, the remounting of the component on the same route definitely wasn't intended here.
Speaking with @schiller-manuel, we'll try swapping out
matchIdforrouteIdto stabilize the key on the same route.