diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index c147a7eccd2..61e4e2d8481 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -342,14 +342,20 @@ export class QueryInfo { variables: WatchQueryOptions["variables"] ) { const { lastWrite } = this; - return !( - lastWrite && - // If cache.evict has been called since the last time we wrote this - // data into the cache, there's a chance writing this result into - // the cache will repair what was evicted. - lastWrite.dmCount === destructiveMethodCounts.get(this.cache) && - equal(variables, lastWrite.variables) && - equal(result.data, lastWrite.result.data) + return ( + // In case variables have changed and there is a race condition where the + // previous variables request finishes after the current variables + // request, skip the cache update. + equal(this.variables, variables) && + !( + lastWrite && + // If cache.evict has been called since the last time we wrote this + // data into the cache, there's a chance writing this result into + // the cache will repair what was evicted. + lastWrite.dmCount === destructiveMethodCounts.get(this.cache) && + equal(variables, lastWrite.variables) && + equal(result.data, lastWrite.result.data) + ) ); }