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

Reset QueryInfo.diff and QueryInfo.dirty after canceling notify timeout #7696

Merged
merged 2 commits into from
Feb 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export class QueryInfo {

private diff: Cache.DiffResult<any> | null = null;

reset() {
cancelNotifyTimeout(this);
this.diff = null;
this.dirty = false;
}

getDiff(variables = this.variables): Cache.DiffResult<any> {
if (this.diff && equal(variables, this.variables)) {
return this.diff;
Expand Down Expand Up @@ -296,10 +302,9 @@ export class QueryInfo {
) {
this.graphQLErrors = isNonEmptyArray(result.errors) ? result.errors : [];

// If there is a pending notify timeout, cancel it because we are
// about to update this.diff to hold the latest data, and we can
// assume the data will be broadcast through some other mechanism.
cancelNotifyTimeout(this);
// Cancel the pending notify timeout (if it exists) to prevent extraneous network
// requests. To allow future notify timeouts, diff and dirty are reset as well.
this.reset();

if (options.fetchPolicy === 'no-cache') {
this.diff = { result: result.data, complete: true };
Expand Down Expand Up @@ -408,7 +413,7 @@ export class QueryInfo {
this.networkStatus = NetworkStatus.error;
this.lastWrite = void 0;

cancelNotifyTimeout(this);
this.reset();

if (error.graphQLErrors) {
this.graphQLErrors = error.graphQLErrors;
Expand Down