-
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
Stop delivering previous data in unrelated loading results. #6566
Conversation
Results with loading:true can still provide data from the cache, but they should never provide data from a previous result, especially since the previous result may have been derived from entirely different variables: #6039 (comment) This is potentially a breaking change for code that relied on result.data not being undefined when result.loading is true, but the bugs that this change will fix are much more serious than the inconvenience of checking the truthiness of result.data before using it. Fixes #6039, as verified by the reproduction provided by @davismariotti: https://codesandbox.io/s/changing-variables-demo-obykj
if (loading) { | ||
const previousData = | ||
this.previousData.result && this.previousData.result.data; | ||
result.data = | ||
previousData && data | ||
? { | ||
...previousData, | ||
...data | ||
} | ||
: previousData || data; | ||
// Fall through without modifying result... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could default result.data
to an empty object here, if we think that will help reduce the risk of this (admittedly late-breaking) change. However, that logic would only apply for React code using QueryData
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing empty objects in data
has gotten us into trouble in the past (as outlined in apollographql/react-apollo#3388), so I'm all for keeping this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @benjamn! (I'm surprised / happy so few tests needed to change for this 🎉)
if (loading) { | ||
const previousData = | ||
this.previousData.result && this.previousData.result.data; | ||
result.data = | ||
previousData && data | ||
? { | ||
...previousData, | ||
...data | ||
} | ||
: previousData || data; | ||
// Fall through without modifying result... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing empty objects in data
has gotten us into trouble in the past (as outlined in apollographql/react-apollo#3388), so I'm all for keeping this as is.
Might be nonsensical, but it's actually very useful in user interfaces with a filter UI. You'd almost never want to completely go back to a global spinner when a filter is changed. We use this a lot in our app, and it's completely broken after this release. Is this coming back as an option? I don't think it is unreasonable to do it explicitly in user code. But this would be the largest breaking change that probably nobody expects in Apollo Client 3. So it would be very important to highlight very largely in the release notes. |
@jfrolich absolutly agree! I was blaming all the breakings on the new cache, but a lot of issues was due to this change and its not mentioned as breaking change (or i did not see it) @jfrolich as a workaround you can do:
|
For our application this was a big surprise, for the same reason above. Given new arguments to same query now results in total empty data :( Its oke to make the software better, but please mention it in the migration doc. |
Is it possible to get the old behavior. For example when typing in a searchField en changing the searchText, it is ok to get the old results for the possible options.... |
Would be nice to optionally have the old behavior back somehow. |
This should have been disabled by default instead of removed entirely. This is a huge breaking change that is not easy to fix. This upgrade is turning out to be quite the headache. |
In an async world it is "nonsensical" to think a user never wants to see old data while they wait for new data. I'm sure there's exceptions, but that's what |
Just a heads up, |
@hwillson FYI I have added this PR to update the v2 -> v3 migration guide, as this breaking change was a challenge to track down. |
Ever since apollographql/react-apollo#1639, Apollo's React functionality has preserved a strange and nonsensical policy of falling back to the previous data for
loading: true
results, even though the previous data may have nothing to do with the current request, as #6039 demonstrates. Results withloading: true
may providedata
from the cache (if any), but they should never simply reuse data from a previous result, which may have been derived using different variables. Instead,result.data
should be undefined for loading states that do not have any partial cache data to provide.This is potentially a breaking change for code that blindly relied on
result.data
being defined wheneverresult.loading
istrue
, but I believe the bugs this change will fix are much more serious than the inconvenience of checking the truthiness ofresult.data
before using it. Still, I wish I'd gotten to this sooner.Fixes #6039, as verified by the reproduction provided by @davismariotti (thanks!).