Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

davismariotti
Copy link

@davismariotti davismariotti commented Mar 10, 2020

Fixes #6039

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #6040 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
src/react/data/QueryData.ts 91.14% <100.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d820fe...ebe5fc1. Read the comment docs.

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor

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)?

Copy link
Author

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!

Copy link
Author

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.

@jpvajda jpvajda added 🏓 awaiting-contributor-response requires input from a contributor 🏓 awaiting-team-response requires input from the apollo team and removed 🏓 awaiting-contributor-response requires input from a contributor labels May 3, 2022
@hwillson
Copy link
Member

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 previousData in #7082. Due to all of this, I believe this PR can now be closed as well, but let us know if you still think something is missing. Thanks!

@hwillson hwillson closed this Aug 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When variables change, data is the previous result in Query Component
4 participants