Skip to content

Commit

Permalink
fix(query-core): don't finalizeThenable of different queries (#8171)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TkDodo authored Oct 12, 2024
1 parent 8e805fb commit 5d69ad7
Show file tree
Hide file tree
Showing 3 changed files with 972 additions and 841 deletions.
5 changes: 4 additions & 1 deletion packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,10 @@ export class QueryObserver<
switch (prevThenable.status) {
case 'pending':
// Finalize the previous thenable if it was pending
finalizeThenableIfPossible(prevThenable)
// and we are still observing the same query
if (query.queryHash === prevQuery.queryHash) {
finalizeThenableIfPossible(prevThenable)
}
break
case 'fulfilled':
if (
Expand Down
Loading

0 comments on commit 5d69ad7

Please sign in to comment.