@tanstack/react-query 4.25.0 → 4.26.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.
@@ -1105,10 +1105,11 @@
1105
1105
  }
1106
1106
 
1107
1107
  if (!isCancelledError(error)) {
1108
- var _this$cache$config$on, _this$cache$config;
1108
+ var _this$cache$config$on, _this$cache$config, _this$cache$config$on2, _this$cache$config2;
1109
1109
 
1110
1110
  // Notify cache callback
1111
1111
  (_this$cache$config$on = (_this$cache$config = this.cache.config).onError) == null ? void 0 : _this$cache$config$on.call(_this$cache$config, error, this);
1112
+ (_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, this.state.data, error, this);
1112
1113
 
1113
1114
  {
1114
1115
  this.logger.error(error);
@@ -1128,7 +1129,7 @@
1128
1129
  fn: context.fetchFn,
1129
1130
  abort: abortController == null ? void 0 : abortController.abort.bind(abortController),
1130
1131
  onSuccess: data => {
1131
- var _this$cache$config$on2, _this$cache$config2;
1132
+ var _this$cache$config$on3, _this$cache$config3, _this$cache$config$on4, _this$cache$config4;
1132
1133
 
1133
1134
  if (typeof data === 'undefined') {
1134
1135
  {
@@ -1141,7 +1142,8 @@
1141
1142
 
1142
1143
  this.setData(data); // Notify cache callback
1143
1144
 
1144
- (_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, data, this);
1145
+ (_this$cache$config$on3 = (_this$cache$config3 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on3.call(_this$cache$config3, data, this);
1146
+ (_this$cache$config$on4 = (_this$cache$config4 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on4.call(_this$cache$config4, data, this.state.error, this);
1145
1147
 
1146
1148
  if (!this.isFetchingOptimistic) {
1147
1149
  // Schedule query gc after fetching
@@ -1411,18 +1413,23 @@
1411
1413
  class Mutation extends Removable {
1412
1414
  constructor(config) {
1413
1415
  super();
1414
- this.options = { ...config.defaultOptions,
1415
- ...config.options
1416
- };
1416
+ this.defaultOptions = config.defaultOptions;
1417
1417
  this.mutationId = config.mutationId;
1418
1418
  this.mutationCache = config.mutationCache;
1419
1419
  this.logger = config.logger || defaultLogger;
1420
1420
  this.observers = [];
1421
1421
  this.state = config.state || getDefaultState();
1422
- this.updateCacheTime(this.options.cacheTime);
1422
+ this.setOptions(config.options);
1423
1423
  this.scheduleGc();
1424
1424
  }
1425
1425
 
1426
+ setOptions(options) {
1427
+ this.options = { ...this.defaultOptions,
1428
+ ...options
1429
+ };
1430
+ this.updateCacheTime(this.options.cacheTime);
1431
+ }
1432
+
1426
1433
  get meta() {
1427
1434
  return this.options.meta;
1428
1435
  }
@@ -1512,7 +1519,7 @@
1512
1519
  const restored = this.state.status === 'loading';
1513
1520
 
1514
1521
  try {
1515
- var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$options$onSettl, _this$options3;
1522
+ var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onSettl, _this$options3;
1516
1523
 
1517
1524
  if (!restored) {
1518
1525
  var _this$mutationCache$c, _this$mutationCache$c2, _this$options$onMutat, _this$options;
@@ -1537,7 +1544,9 @@
1537
1544
  const data = await executeMutation(); // Notify cache callback
1538
1545
 
1539
1546
  await ((_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this));
1540
- await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context));
1547
+ await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context)); // Notify cache callback
1548
+
1549
+ await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, data, null, this.state.variables, this.state.context, this));
1541
1550
  await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, this.state.variables, this.state.context));
1542
1551
  this.dispatch({
1543
1552
  type: 'success',
@@ -1546,16 +1555,18 @@
1546
1555
  return data;
1547
1556
  } catch (error) {
1548
1557
  try {
1549
- var _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onError, _this$options4, _this$options$onSettl2, _this$options5;
1558
+ var _this$mutationCache$c7, _this$mutationCache$c8, _this$options$onError, _this$options4, _this$mutationCache$c9, _this$mutationCache$c10, _this$options$onSettl2, _this$options5;
1550
1559
 
1551
1560
  // Notify cache callback
1552
- await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, error, this.state.variables, this.state.context, this));
1561
+ await ((_this$mutationCache$c7 = (_this$mutationCache$c8 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c7.call(_this$mutationCache$c8, error, this.state.variables, this.state.context, this));
1553
1562
 
1554
1563
  if ("development" !== 'production') {
1555
1564
  this.logger.error(error);
1556
1565
  }
1557
1566
 
1558
- await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context));
1567
+ await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context)); // Notify cache callback
1568
+
1569
+ await ((_this$mutationCache$c9 = (_this$mutationCache$c10 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c9.call(_this$mutationCache$c10, undefined, error, this.state.variables, this.state.context, this));
1559
1570
  await ((_this$options$onSettl2 = (_this$options5 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options5, undefined, error, this.state.variables, this.state.context));
1560
1571
  throw error;
1561
1572
  } finally {
@@ -2992,6 +3003,8 @@
2992
3003
  }
2993
3004
 
2994
3005
  setOptions(options) {
3006
+ var _this$currentMutation;
3007
+
2995
3008
  const prevOptions = this.options;
2996
3009
  this.options = this.client.defaultMutationOptions(options);
2997
3010
 
@@ -3002,13 +3015,15 @@
3002
3015
  observer: this
3003
3016
  });
3004
3017
  }
3018
+
3019
+ (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.setOptions(this.options);
3005
3020
  }
3006
3021
 
3007
3022
  onUnsubscribe() {
3008
3023
  if (!this.listeners.length) {
3009
- var _this$currentMutation;
3024
+ var _this$currentMutation2;
3010
3025
 
3011
- (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.removeObserver(this);
3026
+ (_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
3012
3027
  }
3013
3028
  }
3014
3029