Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: useLoaderData triggers component re rendering even if the route remains unchanged #11477

Closed
xuxin666666 opened this issue Apr 19, 2024 · 1 comment
Labels

Comments

@xuxin666666
Copy link

What version of React Router are you using?

6.22.3

Steps to Reproduce

I use useLoaderData to fetch my data and use it in the Component ComponentA, but there are some problems. ( createBrowserRouter + RouterProvider )

I have a link likes this: <a href="#hash">link</a>. And I click it many times and then ComponentA also re renders many times when the data from useLoaderData remains unchanged. The example is as follows.

see the example

Expected Behavior

ComponentA should be unchanged when the url of page don't change. If possible, I expect ComponentA don't change when only hash changes.

Actual Behavior

Actually, ComponentA re renders even if the url don't change

@timdorr
Copy link
Member

timdorr commented Apr 19, 2024

Those links are causing a location change, so the router is triggered to re-match the current URL. This in turn causes the loader to re-run in case its output has changed. This is expected behavior for both React Router and React itself (a component's state changing, even to the same state, triggers a re-render).

@timdorr timdorr closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants