Skip to content
Closed
Changes from all commits
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
11 changes: 9 additions & 2 deletions packages/query-core/src/queriesObserver.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ export class QueriesObserver<
#lastCombine?: CombineFn<TCombinedResult>
#lastResult?: Array<QueryObserverResult>
#observerMatches: Array<QueryObserverMatch> = []
#observerMap: Map<QueryObserver, number> = new Map()

constructor(
client: QueryClient,
Expand DownExpand Up@@ -81,6 +82,7 @@ export class QueriesObserver<
this.#observers.forEach((observer) => {
observer.destroy()
})
this.#observerMap.clear()
}

setQueries(
Expand DownExpand Up@@ -128,6 +130,11 @@ export class QueriesObserver<
this.#observers = newObservers
this.#result = newResult

this.#observerMap.clear()
newObservers.forEach((observer, index) => {
this.#observerMap.set(observer, index)
})

if (!this.hasListeners()) {
return
}
Expand DownExpand Up@@ -251,8 +258,8 @@ export class QueriesObserver<
}

#onUpdate(observer: QueryObserver, result: QueryObserverResult): void {
const index = this.#observers.indexOf(observer)
if (index !== -1) {
const index = this.#observerMap.get(observer)
if (index !== undefined) {
this.#result = replaceAt(this.#result, index, result)
this.#notify()
}
Expand Down