@tanstack/react-query 5.0.0-alpha.1 → 5.0.0-alpha.2

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.
@@ -908,6 +908,7 @@
908
908
  if (!isCancelledError(error)) {
909
909
  // Notify cache callback
910
910
  this.#cache.config.onError?.(error, this);
911
+ this.#cache.config.onSettled?.(this.state.data, error, this);
911
912
  }
912
913
  if (!this.isFetchingOptimistic) {
913
914
  // Schedule query gc after fetching
@@ -932,6 +933,7 @@
932
933
 
933
934
  // Notify cache callback
934
935
  this.#cache.config.onSuccess?.(data, this);
936
+ this.#cache.config.onSettled?.(data, this.state.error, this);
935
937
  if (!this.isFetchingOptimistic) {
936
938
  // Schedule query gc after fetching
937
939
  this.scheduleGc();
@@ -1277,6 +1279,9 @@
1277
1279
  // Notify cache callback
1278
1280
  await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
1279
1281
  await this.options.onSuccess?.(data, variables, this.state.context);
1282
+
1283
+ // Notify cache callback
1284
+ await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
1280
1285
  await this.options.onSettled?.(data, null, variables, this.state.context);
1281
1286
  this.#dispatch({
1282
1287
  type: 'success',
@@ -1288,6 +1293,9 @@
1288
1293
  // Notify cache callback
1289
1294
  await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
1290
1295
  await this.options.onError?.(error, variables, this.state.context);
1296
+
1297
+ // Notify cache callback
1298
+ await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
1291
1299
  await this.options.onSettled?.(undefined, error, variables, this.state.context);
1292
1300
  throw error;
1293
1301
  } finally {
@@ -2285,14 +2293,12 @@
2285
2293
  #result;
2286
2294
  #queries;
2287
2295
  #observers;
2288
- #observersMap;
2289
2296
  constructor(client, queries) {
2290
2297
  super();
2291
2298
  this.#client = client;
2292
2299
  this.#queries = [];
2293
2300
  this.#result = [];
2294
2301
  this.#observers = [];
2295
- this.#observersMap = {};
2296
2302
  if (queries) {
2297
2303
  this.setQueries(queries);
2298
2304
  }
@@ -2326,14 +2332,12 @@
2326
2332
  // set options for the new observers to notify of changes
2327
2333
  newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
2328
2334
  const newObservers = newObserverMatches.map(match => match.observer);
2329
- const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
2330
2335
  const newResult = newObservers.map(observer => observer.getCurrentResult());
2331
2336
  const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
2332
2337
  if (prevObservers.length === newObservers.length && !hasIndexChange) {
2333
2338
  return;
2334
2339
  }
2335
2340
  this.#observers = newObservers;
2336
- this.#observersMap = newObserversMap;
2337
2341
  this.#result = newResult;
2338
2342
  if (!this.hasListeners()) {
2339
2343
  return;
@@ -2378,7 +2382,7 @@
2378
2382
  const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
2379
2383
  const getObserver = options => {
2380
2384
  const defaultedOptions = this.#client.defaultQueryOptions(options);
2381
- const currentObserver = this.#observersMap[defaultedOptions.queryHash];
2385
+ const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
2382
2386
  return currentObserver ?? new QueryObserver(this.#client, defaultedOptions);
2383
2387
  };
2384
2388
  const newOrReusedObservers = unmatchedQueries.map(options => {
@@ -3008,6 +3012,7 @@
3008
3012
  exports.isCancelledError = isCancelledError;
3009
3013
  exports.isServer = isServer;
3010
3014
  exports.keepPreviousData = keepPreviousData;
3015
+ exports.matchQuery = matchQuery;
3011
3016
  exports.notifyManager = notifyManager;
3012
3017
  exports.onlineManager = onlineManager;
3013
3018
  exports.replaceEqualDeep = replaceEqualDeep;