-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Revalidation triggers fetcher.submit to change #4872
Comments
After further investigation, what's trigger remix/packages/remix-react/components.tsx Line 1260 in 8aacba3
So, what's happening, is I make a change to the URLSearchParams, that triggers the In my case, I don't care about the So, in order to ensure referential stability, we need to either:
I much prefer option 1 because it would actually be a really nice feature to have anyway. It would allow folks to change their code from something like this: const fetcher = useFetcher()
// ...
<button onClick={() => fetcher.submit({hi: 'bob'}, {method: 'post', action: '/some-path'})}>Submit bob</button> To this: const fetcher = useFetcher({
method: 'post',
action: '/some-path',
})
// ...
<button onClick={() => fetcher.submit({hi: 'bob'})}>Submit bob</button> I've seen some folks suggest they would actually prefer this API and I think I agree with them. Also, it would solve the problem of fetcher being referentially stable. |
This should be resolved by remix-run/react-router#10336 which makes |
Should be available in Remix 1.16 once released |
What version of Remix are you using?
1.8.2
Steps to Reproduce
Open this: https://stackblitz.com/edit/node-ikzu57?file=app%2Froutes%2Findex.tsx
Open the browser console
Click "Set searchParams"
Observe the console shows that
fetcher.submit
has changed.Expected Behavior
I expect
fetcher.submit
to be stable so I can safely use it in dependency arrays.Actual Behavior
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.The text was updated successfully, but these errors were encountered: