-
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
Add clearPreviousDataOnLoad option to useQuery (#6039) #6040
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6040 +/- ##
=======================================
Coverage 95.23% 95.24%
=======================================
Files 88 88
Lines 3674 3677 +3
Branches 873 904 +31
=======================================
+ Hits 3499 3502 +3
Misses 153 153
Partials 22 22
Continue to review full report at Codecov.
|
src/react/data/QueryData.ts
Outdated
@@ -420,7 +420,11 @@ export class QueryData<TData, TVariables> extends OperationData { | |||
this.setOptions(options, true); | |||
this.previousData.loading = | |||
this.previousData.result && this.previousData.result.loading || false; | |||
return this.previousData.result = result; | |||
this.previousData.result = result; | |||
if (result.loading && options.clearPreviousDataOnLoad) { |
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.
Wouldn't you only want this to be the case if the variables have changed?
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.
Otherwise the previous data should still be accurate, unless you're using network-only
fetch-policy, in which case I would assume this is handled somewhere else (maybe it isn't)?
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 think you're right, I'll make those changes, thanks!
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've just updated it, but I'm wondering if there's a good way to test this. If I call refetch
, nothing will happen if the variables haven't changed, and if I don't change the variables outside of refetch
, then there won't anything to trigger an update.
Thanks for this @davismariotti and sorry for the long delay. The original issue (#6039) was closed due to the changes made in #6566. We then expanded on those changes to start tracking |
Fixes #6039
Checklist: