-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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]: keep fetcher stable on location changes #9739
Comments
Related comment for stabilizing |
Fixed by #10336 |
Reopening until this is released to npm |
Aligning with Remix here - will close this issue with |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
What version of React Router are you using?
https://stackblitz.com/edit/github-gr13fk?file=src%2Fmain.tsx
Steps to Reproduce
Click the button and see the error
Expected Behavior
The useEffect should not run after changing the search params
Actual Behavior
The fetcher changes when the location changes due to the submitter changing.
Basically, due to the defaultAction changing and that being included in the dependency array, it causes the submit callback to be changed.
I cannot use
fetcher.submit
in a dependency array because any time there's a revalidation on the page, all fetcher.submits are new instances of the submit function. This impacts any situation you want to usefetcher
in a dependency array as well.After further investigation, what's trigger
fetcher.submit
to change is thedefaultAction
dependency: https://github.com/remix-run/remix/blob/8aacba3c4cd23e63ef57a8cb7b68c9d6c88bdb6e/packages/remix-react/components.tsx#L1260 (at least that's what it is in Remix, probably similar in react router).So, what's happening, is I make a change to the URLSearchParams, that triggers the
defaultAction
to change which invalidates thesubmit
on the fetcher which triggers myuseEffect
again.In my case, I don't care about the
defaultAction
because I specify one when I callsubmit
.Originally discussed in #9737
The text was updated successfully, but these errors were encountered: