useQuery returns incorrect data on variable change when using cache
See original GitHub issueWhen the variable of a query changes, and the result for the new variable value is cached (and used, according to the fetchPolicy
), there is an iteration in which data
from useQuery
is incorrect. Instead of showing the cached value, or even undefined
, the value of data
is the previous result of the query, corresponding to the former variable value.
This issue is similar to issue #6300, and I adapted @vishwam sandbox so I can show this issue. Link to the sandbox.
Intended outcome:
Since I’m using cache-first
and the result of my queries have been cached, when the variable change, I expect data
to contain the cached value, or at least undefined
while useQuery hasn’t resolved the cache.
Actual outcome:
data
contains the previous data
value, with results corresponding with the former variable value.
How to reproduce the issue: I found out that useQuery works as inteded from version 3.0.0 (and maybe lower, I haven’t checked) up to version 3.5.0-beta.5. Versions 3.5.0-beta.6 and above have the unintended outcome.
Versions @apollo/client 3.5.0-beta.6
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top GitHub Comments
@gustavoem, yes, the sandbox works as expected since 3.6.0-rc.0. I’ll investigate why my setup doesn’t work.
EDIT: @jpvajda & @gustavoem, turned out some wrong keyArgs were configured in my setup which resulted in different variables matching on the same cached query. So, for me the issue is solved by updating apollo-client and setting the correct keyArgs.
The sandbox seem to be working as expected with 3.6.8