-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Infinite loop when using fetcher.load in latest Remix releases #6072
Comments
I face this problem too. Any update on this? |
I believe this is an unlisted bug/change that only affects the latest versions. However there is a work around provided by brocktho in the discord chat useEffect(() => {
if (shouldFetch && fetcher.state === 'idle') {
fetcher.load('/fetchRoute');
setShouldFetch(false);
}
}, [fetcher, shouldFetch]); Here's a summary of why this works from Ryan Florence
However as an unlisted change that breaks previously working code, I still believe this is a bug |
probably dup of #6014 + docs are here https://remix.run/docs/en/main/hooks/use-fetcher#fetcherload function SomeComponent() {
const fetcher = useFetcher();
useEffect(() => {
if (fetcher.state === "idle" && fetcher.data == null) {
fetcher.load("/some/route");
}
}, [fetcher]);
fetcher.data; // the data from the loader
} |
Yes, I believe that you should always check |
This turns out to be due to the usage of |
This is fixed in |
What version of Remix are you using?
1.14.0 (also on 1.15)
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
1.) Create a resource-route (or any loader) that returns anything. In this case I'm returning
json({hello: 'world'})
2.) In any route, create a state variable to track to see if it has been invoked. For example
3.) Note the infinite loop / crash that happens
![image](https://user-images.githubusercontent.com/16729071/232183037-fd12da86-7379-404d-8138-708bad6f8085.png)
-Note-
I am upgrading my Remix from an earlier version where my existing code worked fine. This bug only appeared after upgrading and I was able to replicate in a code sandbox here:
https://codesandbox.io/p/sandbox/hopeful-night-z2lsum?file=%2Fapp%2Froutes%2Findex.tsx&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A7%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A7%7D%5D
Expected Behavior
The fetcher should only load once
Actual Behavior
An infinite loop occurs, crashing the page.
The text was updated successfully, but these errors were encountered: