Skip to content

Commit 5d69ad7

Browse files
authored
fix(query-core): don't finalizeThenable of different queries (#8171)
* fix(query-core): don't finalizeThenable of different queries if we have multiple promises in-flight, once they resolve, we need to make sure to not finalize with data / error from a different key; otherwise, we might see intermediate data of non-matching keys * chore: extract promise tests to their own file * test: add a test case for not resolving with intermediate data * fix: only stop finalizing if we were previously in pending state this makes sure we can read stale data from entries when switching to them immediately * chore: add another test for background updates
1 parent 8e805fb commit 5d69ad7

File tree

3 files changed

+972
-841
lines changed

3 files changed

+972
-841
lines changed

packages/query-core/src/queryObserver.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,10 @@ export class QueryObserver<
621621
switch (prevThenable.status) {
622622
case 'pending':
623623
// Finalize the previous thenable if it was pending
624-
finalizeThenableIfPossible(prevThenable)
624+
// and we are still observing the same query
625+
if (query.queryHash === prevQuery.queryHash) {
626+
finalizeThenableIfPossible(prevThenable)
627+
}
625628
break
626629
case 'fulfilled':
627630
if (

0 commit comments

Comments
 (0)