You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Component A asks for people named John, retrieving the fields id and name. The results are stored in the cache.
useQuery({ query people(name: "john") { id, name } })
Component B asks for people named Sarah, retrieving the fields id and age. It is a network-only request so does not read from the cache. Note notifyOnNetworkStatusChange is set to true.
Component B re-renders with a different name - John. It is still a network-only request. It is expected that the query goes into a loading state and then returns the fields id and age, the same as step 2.
Step 3 does not work as expected. The cached result for step 1 is returned instantly, instead of loading the latest data. This is unexpected because
the cached data does not match what we want - we asked for id/age, we get id/name from the cache. the data is partial. we don't have partial results enabled.
While looking into this problem we found a part of the code that seemed to be responsible for this change in behaviour when using notifyOnNetworkStatusChange:
We also have noticed that when fetchPolicy is set to cached-and-network, despite a query is requesting new fields, Apollo returns cached partial data ( received from a similar query made previously ). This causes missing fields getting used incorrectly and cause TypeError, result in crashes in app.
Intended outcome:
id
andname
. The results are stored in the cache.id
andage
. It is a network-only request so does not read from the cache. NotenotifyOnNetworkStatusChange
is set totrue
.id
andage
, the same as step 2.Actual outcome:
Step 3 does not work as expected. The cached result for step 1 is returned instantly, instead of loading the latest data. This is unexpected because
id/age
, we getid/name
from the cache. the data is partial. we don't have partial results enabled.network-only
(https://www.apollographql.com/docs/react/data/queries/#network-only) states that it shouldn't return things from the cache (whether partial or not).How to reproduce the issue:
reproduction using error template: https://github.com/mingjuitsai/react-apollo-error-template
npm install; npm start
Versions
Extra notes
While looking into this problem we found a part of the code that seemed to be responsible for this change in behaviour when using
notifyOnNetworkStatusChange
:apollo-client/src/core/QueryManager.ts
Lines 1436 to 1442 in b214dd1
If
network-only
andshouldNotify
is true (set when usingnotifyOnNetworkStatusChange
), the (potentially partial) cached results are returned.This code was introduced in #7761.
It looks like there have been on comments on this PR raising a similar problem: #7761 (comment)
Also seems to be related to #6941.
Thanks.
The text was updated successfully, but these errors were encountered: