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

[Feature]: Performance problem with useNavigate #10743

Closed
cloudcode-hungary opened this issue Jul 28, 2023 · 2 comments
Closed

[Feature]: Performance problem with useNavigate #10743

cloudcode-hungary opened this issue Jul 28, 2023 · 2 comments
Labels

Comments

@cloudcode-hungary
Copy link

What version of React Router are you using?

6.4.1

Steps to Reproduce

The useNavigate hook causes a rerender of the components any time the url changes.

  • I have a very render heavy component (https://mui.com/x/react-data-grid/)
  • I need to pass an onRowClick handler which calls navigate() to the clicked row
  • I have some other actions in the datagrid, like selecting a few rows and then opening a modal to do stuff -> which is also written to the url /path/to/list?modal_action=stuff&modal_id=1,2

Opening the modal lags very much, because the whole list is re-rendered through useNavigate() - as useNavigate gets updated when the query string changes.

Expected Behavior

I expect useNavigate not to change, it should remain stable and should not depend on the current url.
(I am not using any relative navigation, always absolute, so it really should not care about the current location).

Is it possible to get a stable alternative besides useNavigate() with limitations maybe like not supporting relative navigation, but performance benefits? Or is there any other workaround to this problem, like navigating through some browser API? If I call window.location.assign the page reloads.

Actual Behavior

useNavigate changes.

@cloudcode-hungary cloudcode-hungary changed the title [Bug]: Performance problem with useNavigate [Feature]: Performance problem with useNavigate Jul 28, 2023
@cloudcode-hungary
Copy link
Author

I have checked the deepest bottoms of the navigate function, and in the end it calls window.history.pushState().
But simply calling pushState does not rerender the components, the url changes but everything remains.

@brophdawg11
Copy link
Contributor

useNavigate is unstable and must remain so in BrowserRouter in order to support relative routing.

#7634 and #9588 stabilized the identity of useNavigate when using RouterProvider (on v6.11.0 and later) so that is the recommended workaround.

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
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