useQuery loading state stays true after fetch finishes
See original GitHub issueThere 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:
- Created 3 years ago
- Reactions:16
- Comments:27 (5 by maintainers)
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.
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