@tanstack/query-core 4.26.1 → 4.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.26.1",
3
+ "version": "4.29.1",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -131,33 +131,35 @@ export class QueriesObserver extends Subscribable<QueriesObserverListener> {
131
131
  queries: QueryObserverOptions[],
132
132
  ): QueryObserverMatch[] {
133
133
  const prevObservers = this.observers
134
+ const prevObserversMap = new Map(
135
+ prevObservers.map((observer) => [observer.options.queryHash, observer]),
136
+ )
137
+
134
138
  const defaultedQueryOptions = queries.map((options) =>
135
139
  this.client.defaultQueryOptions(options),
136
140
  )
137
141
 
138
142
  const matchingObservers: QueryObserverMatch[] =
139
143
  defaultedQueryOptions.flatMap((defaultedOptions) => {
140
- const match = prevObservers.find(
141
- (observer) =>
142
- observer.options.queryHash === defaultedOptions.queryHash,
143
- )
144
+ const match = prevObserversMap.get(defaultedOptions.queryHash)
144
145
  if (match != null) {
145
146
  return [{ defaultedQueryOptions: defaultedOptions, observer: match }]
146
147
  }
147
148
  return []
148
149
  })
149
150
 
150
- const matchedQueryHashes = matchingObservers.map(
151
- (match) => match.defaultedQueryOptions.queryHash,
151
+ const matchedQueryHashes = new Set(
152
+ matchingObservers.map((match) => match.defaultedQueryOptions.queryHash),
152
153
  )
153
154
  const unmatchedQueries = defaultedQueryOptions.filter(
154
- (defaultedOptions) =>
155
- !matchedQueryHashes.includes(defaultedOptions.queryHash),
155
+ (defaultedOptions) => !matchedQueryHashes.has(defaultedOptions.queryHash),
156
156
  )
157
157
 
158
+ const matchingObserversSet = new Set(
159
+ matchingObservers.map((match) => match.observer),
160
+ )
158
161
  const unmatchedObservers = prevObservers.filter(
159
- (prevObserver) =>
160
- !matchingObservers.some((match) => match.observer === prevObserver),
162
+ (prevObserver) => !matchingObserversSet.has(prevObserver),
161
163
  )
162
164
 
163
165
  const getObserver = (options: QueryObserverOptions): QueryObserver => {
package/src/query.ts CHANGED
@@ -118,7 +118,7 @@ interface ContinueAction {
118
118
 
119
119
  interface SetStateAction<TData, TError> {
120
120
  type: 'setState'
121
- state: QueryState<TData, TError>
121
+ state: Partial<QueryState<TData, TError>>
122
122
  setStateOptions?: SetStateOptions
123
123
  }
124
124
 
@@ -212,7 +212,7 @@ export class Query<
212
212
  }
213
213
 
214
214
  setState(
215
- state: QueryState<TData, TError>,
215
+ state: Partial<QueryState<TData, TError>>,
216
216
  setStateOptions?: SetStateOptions,
217
217
  ): void {
218
218
  this.dispatch({ type: 'setState', state, setStateOptions })