diff --git a/.changeset/fresh-mice-listen.md b/.changeset/fresh-mice-listen.md new file mode 100644 index 0000000000..db592344ac --- /dev/null +++ b/.changeset/fresh-mice-listen.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': patch +--- + +Skip unused result tracking when notifying `useQueries` listeners without a `combine` function. diff --git a/packages/query-core/src/queriesObserver.ts b/packages/query-core/src/queriesObserver.ts index c537b557ca..b3fb41991e 100644 --- a/packages/query-core/src/queriesObserver.ts +++ b/packages/query-core/src/queriesObserver.ts @@ -256,7 +256,7 @@ export class QueriesObserver< #shouldSkipCombine(): boolean { return ( - this.#options?.combine !== undefined && + !this.#options?.combine || this.#observers.some((observer, index) => { return ( observer.options.suspense && this.#result[index]?.data === undefined @@ -310,12 +310,14 @@ export class QueriesObserver< #notify(): void { if (this.hasListeners()) { - const newTracked = this.#trackResult(this.#result, this.#observerMatches) const shouldSkipCombine = this.#shouldSkipCombine() const previousResult = this.#combinedResult const newResult = shouldSkipCombine ? previousResult - : this.#combineResult(newTracked, this.#options?.combine) + : this.#combineResult( + this.#trackResult(this.#result, this.#observerMatches), + this.#options?.combine, + ) if (shouldSkipCombine || previousResult !== newResult) { notifyManager.batch(() => {