-
Notifications
You must be signed in to change notification settings - Fork 783
useQuery Hook always return true on loading state #3361
Comments
Having the same issue |
I'm having the exact same issue. |
I'm running into something similar, although I've only observed it in a mocked Cypess test environment where fetch is mocked and resolved immediately with the query data. It is working in almost all of our tests (and was working always consistently prior to updating to the latest react-apollo version), but we now have a few tests with a query that will get caught in a loading state about 50% of the time (sometimes more or less than 50% depending on the test). It seems to be some kind of race condition because if we artificially add a delay of 500 ms, the tests always passes again. Tried to dig in a little bit to see where things might be going wrong, but haven't hit any conclusions yet. Edit:
For the case that gets stuck in loading: The case that doesn't get stuck in loading: So it seems like the problem for me has to do with the query resolving too early, which results in it getting stuck. I'm guessing something with the Observable isn't setup in time when the query resolves so quickly. This would make sense given that an artificial delay helps resolve whatever race is going on. |
Having the same issue as well. |
@Dalejan did you try with "no-cache" option for fetch-policy ? I have a similar issue, but it "works" if I disable the cache ("cache-and-network", "network-only", etc don't work). |
Same. And |
ok, we fixed our problem, so our solution, which may not be relavant in this case: We use fragments on unions and interface (https://www.apollographql.com/docs/react/advanced/fragments/#fragments-on-unions-and-interfaces) For some reason, it was working with react-apollo 2.4.1 without the IntrospectionFragmentMatcher . But not anymore in 2.5.3 and above, and it showed the behavior described in the @Dalejan initial post: re-fetching indefinitely. Setting up the IntrospectionFragmentMatcher fixed it :) Hope it helps some of you :) |
In my case, since this is not happening more often than it is, this seems to mitigate it: const useFixLoading = () => {
const refetchRef = useRef(() => {});
const timeoutRef = useRef(null);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (timeoutRef.current != null) {
clearTimeout(timeoutRef.current);
timeoutRef.current = null;
}
if (isLoading) {
timeoutRef.current = setTimeout(() => {
refetchRef.current();
}, 3000);
}
}, [isLoading]);
return (loading, refetch) => {
setIsLoading(loading);
refetchRef.current = refetch;
};
};
const MyQuery = (...) => {
const fixLoading = useFixLoading();
return (
<Query
query={query}
variables={variables}
fetchPolicy="network-only"
>
{({ loading, error, data, refetch }) => {
fixLoading(loading, refetch);
// ..
}}
</Query>
);
}; |
Could someone test this out with React Apollo 3.1.0 and let us know if this is still an issue? thanks! |
I am also experiencing this issue. I tried to follow @TLadd's approach and artificially add a delay of 500 ms, but the results are inconsistent.
|
Ran into this same issue today (
This did the trick for me (although you will lose the benefits of cache).
|
Is anyone still seeing this issue with React Apollo 3.1.0? |
Not so far :) |
Thanks @mpgon - I'll mark this as resolved, but if anyone is still encountering this let me know. |
@hwillson Encountered this again. I don't know if anything that was done would impact the frequency of when this occurs, because it appears to be happening less since I upgraded to 3.1.0, but definitely still happening. |
@hwillson Just saw this in our app again with 3.1.2, happening in a specific component and only on the first load. But in that situation it is consistent. I'm not able to create a small repro so not sure how to best help :/ Like the above commenters mentioned earlier this can be 'fixed' by disabling the cache. |
@hwillson I'm seeing this issue, too, using the latest version of hooks... @Dalejan please consider reopening this issue
My query is a local query and therefore the 'no-cache' solution is absolutely not an option, not that it is really a solution anyways Edit: Initially, I was using |
I can confirm this is still occurring in 3.1.3. |
We are seeing this on 3.1.3. |
@hwillson can you re-open this issue? |
I seem to have this same issue with @apollo/client 3.0.0-beta.7. I'm running on react-native (expo) while connected to the React Native Debugger. If I disconnect from the debugger, I don't seem to have this issue. The version of React Native Debugger I'm using is 0.10.2. Perhaps this issue is with RND? |
I found a workaround for 3.1.3, which is to set |
I just encountered this issue as well in 3.1.3... @hwillson can you reopen this issue? |
we can fixed it with follow code: ...
const client = React.useRef(query.client());
const { data, loading, error } = useQuery(`GQL`, {
variables,
client: client.current,
});
... |
I am having the same issue, major blocker |
I have the same issue and had to use |
This is definitely still happening in 3.1.3. Having to add Please re-open this issue. |
I have the same issue too, I can't fetch data when using anything with |
I've submitted a new issue to request that this issue be reopened. |
I have I think the same issue right now, so for example, my code is
|
I don't know how to explain this, but I have this happen when a totally different async function on the same page fails. No idea why/how, but fixing that random promise rejection fixed this for me |
What you describe reminds me this old thread from Dan Abramov : https://mobile.twitter.com/dan_abramov/status/770914221638942720?lang=en |
Encountered issue on 3.1.3 |
I have the same issue on 3.1.3. I tried |
Upgrading to 3.1.3 fixed the issue we were seeing. |
Experiencing the same issue on 3.1.3. |
ApolloClient 3.0.0-beta. In my case |
This comment helped me a lot ! Thx !! I had the following issue :
The issue was created, not by react-apollo, but by the way we wrote onError in I solved this by removing |
Same issue with |
same on : "apollo-cache": "1.3.4", |
Hi, im having this issue on every useQuery hook implementation: the data is actually fetched from the backend (i can see it in the network devops from google), but the loading state of the query is always true, this causes an infinite loop that doesn't let me show any data, only loading template.
Intended outcome:
Data response from useQuery hook same as preview or response from network devops
loading = true, then false
error = undefined
Actual outcome:
data = {}
loading = always true
error = undefined
How to reproduce the issue:
Imports:
Query:
Function:
Version
NOTE: I have already tried with react-apollo instead of apollo-boost, same result
System:
OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
Binaries:
Node: 8.10.0 - /usr/bin/node
npm: 6.8.0 - /usr/local/bin/npm
Browsers:
Chrome: 75.0.3770.142
Firefox: 68.0.1
npmPackages:
apollo-boost: ^0.4.4 => 0.4.4
react-apollo: ^3.0.0 => 3.0.0
The text was updated successfully, but these errors were encountered: