-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useQuery with fetchPolicy: 'network-only', returns stale cached results. #7058
Comments
@benjamn @dmt0 I think that we face almost the same issue with the stale data in cache when we make a Query with fetchPolicy='network-only'. In my example : https://github.com/apollographql/apollo-client/issues/7048 I see a network request made to the server however the data returned by the GraphQL server is not rendered by AC3 and instead Apollo Client cache pulls data from the cache and ignores backend returned data. As if Apollo Client v3 does something to prevent cache overwriting because normally when you specify fetchPolicy='network-only' AC3 should then update the cache with backend data and does this automatically by matching the ID coming from the server and the ID of the object to be modified in cache. I think that maybe there could be another step to do in order to update the existing data in cache .. This stuff works well with Apollo Client 2 (with returning ID) and now it seems that it is broken. I'm blocked right now :/ |
Similar to #7045 (comment) ? |
@magicmark I've seen your issue too. Doesn't seem like it's the same, I didn't have a network error. |
This bug is still there as of v3.4.0-beta.18 |
I am also experiencing a similar (maybe the same?) issue @dmt0 I am on v.3.5.9 |
And here's a simplified version in a sandbox https://codesandbox.io/s/refetch-cache-update-fail-k5s7x6?file=/src/exchange-rates.js |
+1 |
+1 |
1 similar comment
+1 |
Yup, can confirm. This bug shows up on |
This is very similar to (or maybe the same as) #7048. I'm using
useQuery
withfetchPolicy: 'network-only'
. In certain cases, it does not make a network request, and returns not just cached results, but stale cached results.In my app I have asynchronous processes on backend, that take forever. After I do a mutation, I do an optimistic update with
cache.modify
inupdate
function, and thenstartPolling
on a query to continuously check if the operation is complete. This worked very well when I used Apollo V2. Not after the upgrade to V3.Here's my custom hook that manages mutations and status checks:
Intended outcome:
startPolling
...
console.log
's after the query should both print stuff that query pulled from backend.Actual outcome:
console.log
:So the cache actually did update correctly after
cache.modify
, but thedata
returned byuseQuery
returns some stale cache.If I remove
fetchPolicy: 'network-only'
, I get the correct cached result - which almost works for me, except if the above example gets extended to also doremoveItem
, and then a user starts to add and remove things quickly, things start getting out of sync and weird stuff happens. Again - this exact code (minus the API adjustments for V3) worked perfectly on V2.How to reproduce the issue:
Above
Versions
System:
OS: macOS 10.15.6
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Browsers:
Chrome: 85.0.4183.121
npmPackages:
@apollo/client: ^3.2.0 => 3.2.0
apollo-link-logger: git://github.com/dmt0/apollo-link-logger.git#support-apollo-v3 => 0.0.0-development
apollo-upload-client: ^14.1.2 => 14.1.2
npmGlobalPackages:
apollo-link-logger: 0.0.0-development
The text was updated successfully, but these errors were encountered: