router icon indicating copy to clipboard operation
router copied to clipboard

fix: memoize matches provider data

Open rstrand opened this issue 3 years ago • 2 comments

The MatchesProvider value changes on every render every time the provider is rendered. This causes any component using the useMatch or useMatches hook to re-render 3 times when navigating. Two of these renders occur before the routes update.

I am using the useMatch hook to access route loader data on my pages, and they currently re-render twice before unmounting because of a route change.

This PR fixes this by performing a shallow compare on the RouteMatch array and returning the old value if they are equal.

rstrand avatar Aug 19 '22 21:08 rstrand

@rstrand is attempting to deploy a commit to the Tanstack Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Aug 19 '22 21:08 vercel[bot]

I would love to see this change accepted. We've been bitten by the double re-render before the route is updated several times.

yergom avatar Sep 15 '22 08:09 yergom

This will need to be reworked for TanStack Router

tannerlinsley avatar Nov 10 '22 15:11 tannerlinsley