loading is always True in Query render prop
I am using query render prop, which been wrapped by a redux render prop, which provides a new query for a new fetch. But when the new fetch been triggered, the loading is always true in the Query render prop.
expected: the loading state should be false once data has been returned actual: the loading state is always true
It seems that the loading is always true if data is the same? but it's not consistant
apollo-client: 2.2.8 react-apollo: 2.1.3
Code:
<WithRedux id={id}>
{
({ d }) => {
return (
<Query query={getQuery(d)}>
{({ loading, error, data, refetch, networkStatus }) => {
console.log('.....networkStatus', networkStatus);
console.log('.....loading', loading);
console.log('.....data', data);
if (error) return <CompPlaceholder cnt={1} template={0} />;
if (loading) return <CompPlaceholder cnt={1} template={1} />;
if (data && Object.keys(data).length > 0) {
if (data.flightInfo && data.flightInfo.length > 0) {
return (
<DetailFlightInfoCard id={id} data={data.flightInfo} />
);
}
return null;
}
return null;
}}
</Query>
);
}
}
</WithRedux>
apollo client with batchLink and cache
new ApolloClient({
link: batchLink,
cache: new InMemoryCache(),
connectToDevTools: true,
});
I can confirm.
Facing the same issue using the same versions
Facing same problem. When response data exceeded certain size, it didn't catch the response with data.
I’m seeing loading === true And networkStatus === 1 when using skip={true} which I certainly didn’t expect. No request is actually being sent (which is correct) but the props passed to the render function would suggest one is.
same problems please fix it.
Experiencing the same thing here on 2.3.2.

Above you can see two consecutive queries, both returning an empty array as data. First one works fine, switching loading flag to true and then back to false. Second one, freezes at true and never flips back.

Network tab shows both /graphql requests completed successfully and returning the same payload.
After digging around Query.tsx code, I found out that the main issue is that its render() method never gets called if the same data is fetched twice from the network, so children render function is also never invoked.
This seems to be relying in this.queryObservable to trigger a next callback call, which never happens under these conditions - so issue might actually lie in the client.
Ok, finally discovered the underlying cause. It's this line on apollo-client preventing consecutive, identical results from being propagated to the observer. The actual fetched data is compared here.
if (observer.next) {
if (
previouslyHadError ||
!observableQuery ||
// This is causing the issue 👇
observableQuery.isDifferentFromLastResult(resultFromStore)
) {
try {
observer.next(resultFromStore);
} catch (e) {
// Throw error outside this control flow to avoid breaking Apollo's state
setTimeout(() => {
throw e;
}, 0);
}
}
}
Replacing observableQuery.isDifferentFromLastResult(resultFromStore) with just true makes the problem go away and <Query> re-renders properly.
Follow up: it turns out my particular issue was caused by apollo-cache-hermes, which I have been using as a substitution for apollo-inmemory-cache. Switching back to latest apollo-inmemory-cache resolved the problem for me.
You can find a repro case here:
I'm not using the <Query /> component, but I'm also having this problem with the graphql function if I use skip() and have two queries that result in the same data. Remove skip(), or remove one of the components that tries to fetch, and it works fine.
I seem to be encountering this same issue even without any cache in place. Using a <Query /> with the prop fetchPolicy="network-only" passed, if I make a query that is functionally the same as the previous query (for instance, the fields are the same but in a different order) and the response is the same the loading argument will come back true after the request has successfully completed.
apollo-client: "2.4.2"
react-apollo: "2.1.11"
For what it's worth, this comment from #1186 recommends passing the notifyOnNetworkStatusChange props, which worked for me.
same issue
react-apollo @ 2.5.2
apollo-client @ 2.5.1
notifyOnNetworkStatusChange did not work
@nfantone you say that changing the line observableQuery.isDifferentFromLastResult(resultFromStore) to true solves the problem. How did you end up determining that apollo-cache-hemes was the actual source of your issues?
If we know the solution to the problem, could we make a pull request to fix it?
The notifyOnNetworkStatusChange: true workaround worked well for us using apollo-client 2.4.8 and earlier. But this workaround no longer works with apollo-client 2.5.1
Using apollo-client 2.5.1, the original issue of the second identical data not causing loading to be set to false returns.
@mac-s-g in my experiene the work around only works for 2.4.x and older
@baleeds It's been some time now and I don't really remember details, but yours is a good question. Both approaches worked: replacing apollo-cache-hermes and forfeiting isDifferentFromLastResult validation. So my guess is that resultFromStore ends up being different in each cache implementation, somehow.
https://github.com/apollographql/react-apollo/pull/2840 should help address the issues mentioned here, starting from https://github.com/apollographql/react-apollo/issues/1931#issuecomment-471242011. We're hoping to have a new react-apollo release published either later today / tomorrow.
@city41 rolling back to 2.4.1 fixed the issue for now. thank you!
We just ran into this.. Any updates on a fix?
We just ran into this.. Any updates on a fix?
Could this be the fix for you: notifyOnNetworkStatusChange: true ? I works for me.
@ciulic nope - that didn't fix. ended up having to expose the requestTime on the api so that i could make the responses distinct, which.. is very hacky