Unexpected re-render caused by `MatchRoute`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Router
Describe the bug
MatchRoute will an unexpected error, if the child component of MatchRoute is a function:
// unexpected re-render
<MatchRoute to="/posts/$postId" params={{ postId: '1' }}>
{(matches) => {
return matches && <Post1Component />
}}
</MatchRoute>
// expected behavior
<MatchRoute to="/posts/$postId" params={{ postId: '2' }}>
<Post2Component />
</MatchRoute>
If you are at /posts/1, then go to /posts/2. An unexpected re-render of <Post1Component /> will happen.
Your Example Website or App
https://stackblitz.com/~/github.com/gz65555/tanstack-unexpected-rerender
Steps to Reproduce the Bug or Issue
- Go to the reproduce url
- click "Posts"
- click "Post1"
- click "Post2"
You can see the bug from devtools:
Expected behavior
I expected that the console should be:
render post1
render post2
Platform
- OS: macOS
- Browser: chrome
- Version: 133
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and follow the listed navigation steps: Posts, Post1, then Post2. Inspect MatchRoute behavior with a function child using the browser devtools. Done means navigating from post 1 to post 2 logs only “render post1” and “render post2”, without an unexpected Post1Component re-render.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100