question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useQuery loading state stays true after fetch finishes

See original GitHub issue

There is an issue with useQuery loading state remaining true if a cached query result is displayed and the subsequent variable changes return the same result as the cached one.
See codesandbox for the steps to reproduce.

changing the fetchPolicy to network-only or cache-and-network fixes the issues This issues appeared after beta-46 refactor, works as expected in beta-45

Intended outcome: the loading reverts to false once the fetch is finished

Actual outcome: the loading stays true until the you change the query variable so that the query returns results that are different from the cached one being displayed .

How to reproduce the issue: https://codesandbox.io/s/nifty-ptolemy-1308j?file=/src/App.js

Versions System: OS: Windows 10 10.0.19041 Binaries: Node: 13.8.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files\nodejs\yarn.CMD npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 44.19041.1.0 npmPackages: @apollo/client: ^3.0.0-beta.49 => 3.0.0-beta.50 @apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3 @apollo/link-retry: ^2.0.0-beta.3 => 2.0.0-beta.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:27 (5 by maintainers)

github_iconTop GitHub Comments

26reactions
hwillsoncommented, Jun 4, 2020

Thanks for the great reproduction and details here. This issue is being caused by the way we snapshot and track differences between results, to help prevent unnecessary computations. For example, removing the isDifferentFromLastResult call from this line fixes the issue:

https://github.com/apollographql/apollo-client/blob/2d61e5c936c2bcb2aa62f4eb7c6f82b773b962ab/src/core/ObservableQuery.ts#L594

We’ll tweak the snapshot approach a bit, and have a fix for this out shortly.

11reactions
dalley8626commented, Apr 30, 2022

I somehow found the solution for it, I believe that versino 3.6.0 is very much catered for react 18, which in my case expo’s sdk only support up to react 17, therefore using apollo/client: 3.5.4 worked, along with “graphql”: “^16.3.0”. I hope that helps for u too @MAK-Denis

Read more comments on GitHub >

github_iconTop Results From Across the Web

'loading' remains true when loading data with 'useQuery' using ...
Version 3.6 implements useQuery using useSyncExternalStore API from React 18. Since expo currently supports React 17 you can solve the issue ...
Read more >
When does useQuery think that a query is "loading"? - Help
The resolver waits a second, then returns some hardcoded data. I was expecting that useQuery(). loading === true until the resolver completed, ...
Read more >
useQuery | TanStack Query Docs
fetching : Is true whenever the queryFn is executing, which includes initial loading as well as background refetches. · paused : The query...
Read more >
Mastering Mutations in React Query | TkDodo's blog
useMutation will track the state of a mutation, just like useQuery does for queries. It'll give you loading, error and status fields to...
Read more >
Loading state on API call with useEffect : r/reactjs - Reddit
Your component will rerender to reflect those state changes before and after the fetch, which is what you want, but you don't need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found