Skip to content

Commit

Permalink
Reset QueryInfo.{diff,dirty} after canceling notify timeout in mark{R…
Browse files Browse the repository at this point in the history
…esult,Error} (#7696)
  • Loading branch information
jcreighton committed Feb 14, 2021
1 parent 7b9bf8b commit 911a19a
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit 911a19a

Please sign in to comment.