@tanstack/react-query 4.12.0 → 4.13.4

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.
@@ -1136,9 +1136,11 @@
1136
1136
  this.isFetchingOptimistic = false;
1137
1137
  },
1138
1138
  onError,
1139
- onFail: () => {
1139
+ onFail: (failureCount, error) => {
1140
1140
  this.dispatch({
1141
- type: 'failed'
1141
+ type: 'failed',
1142
+ failureCount,
1143
+ error
1142
1144
  });
1143
1145
  },
1144
1146
  onPause: () => {
@@ -1166,7 +1168,8 @@
1166
1168
  switch (action.type) {
1167
1169
  case 'failed':
1168
1170
  return { ...state,
1169
- fetchFailureCount: state.fetchFailureCount + 1
1171
+ fetchFailureCount: action.failureCount,
1172
+ fetchFailureReason: action.error
1170
1173
  };
1171
1174
 
1172
1175
  case 'pause':
@@ -1182,6 +1185,7 @@
1182
1185
  case 'fetch':
1183
1186
  return { ...state,
1184
1187
  fetchFailureCount: 0,
1188
+ fetchFailureReason: null,
1185
1189
  fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
1186
1190
  fetchStatus: canFetch(this.options.networkMode) ? 'fetching' : 'paused',
1187
1191
  ...(!state.dataUpdatedAt && {
@@ -1200,7 +1204,8 @@
1200
1204
  status: 'success',
1201
1205
  ...(!action.manual && {
1202
1206
  fetchStatus: 'idle',
1203
- fetchFailureCount: 0
1207
+ fetchFailureCount: 0,
1208
+ fetchFailureReason: null
1204
1209
  })
1205
1210
  };
1206
1211
 
@@ -1217,6 +1222,7 @@
1217
1222
  errorUpdateCount: state.errorUpdateCount + 1,
1218
1223
  errorUpdatedAt: Date.now(),
1219
1224
  fetchFailureCount: state.fetchFailureCount + 1,
1225
+ fetchFailureReason: error,
1220
1226
  fetchStatus: 'idle',
1221
1227
  status: 'error'
1222
1228
  };
@@ -1261,6 +1267,7 @@
1261
1267
  errorUpdateCount: 0,
1262
1268
  errorUpdatedAt: 0,
1263
1269
  fetchFailureCount: 0,
1270
+ fetchFailureReason: null,
1264
1271
  fetchMeta: null,
1265
1272
  isInvalidated: false,
1266
1273
  status: hasData ? 'success' : 'loading',
@@ -1465,9 +1472,11 @@
1465
1472
 
1466
1473
  return this.options.mutationFn(this.state.variables);
1467
1474
  },
1468
- onFail: () => {
1475
+ onFail: (failureCount, error) => {
1469
1476
  this.dispatch({
1470
- type: 'failed'
1477
+ type: 'failed',
1478
+ failureCount,
1479
+ error
1471
1480
  });
1472
1481
  },
1473
1482
  onPause: () => {
@@ -1550,7 +1559,8 @@
1550
1559
  switch (action.type) {
1551
1560
  case 'failed':
1552
1561
  return { ...state,
1553
- failureCount: state.failureCount + 1
1562
+ failureCount: action.failureCount,
1563
+ failureReason: action.error
1554
1564
  };
1555
1565
 
1556
1566
  case 'pause':
@@ -1567,6 +1577,8 @@
1567
1577
  return { ...state,
1568
1578
  context: action.context,
1569
1579
  data: undefined,
1580
+ failureCount: 0,
1581
+ failureReason: null,
1570
1582
  error: null,
1571
1583
  isPaused: !canFetch(this.options.networkMode),
1572
1584
  status: 'loading',
@@ -1576,6 +1588,8 @@
1576
1588
  case 'success':
1577
1589
  return { ...state,
1578
1590
  data: action.data,
1591
+ failureCount: 0,
1592
+ failureReason: null,
1579
1593
  error: null,
1580
1594
  status: 'success',
1581
1595
  isPaused: false
@@ -1586,6 +1600,7 @@
1586
1600
  data: undefined,
1587
1601
  error: action.error,
1588
1602
  failureCount: state.failureCount + 1,
1603
+ failureReason: action.error,
1589
1604
  isPaused: false,
1590
1605
  status: 'error'
1591
1606
  };
@@ -1617,6 +1632,7 @@
1617
1632
  data: undefined,
1618
1633
  error: null,
1619
1634
  failureCount: 0,
1635
+ failureReason: null,
1620
1636
  isPaused: false,
1621
1637
  status: 'idle',
1622
1638
  variables: undefined
@@ -2477,7 +2493,6 @@
2477
2493
  if (options.select && typeof placeholderData !== 'undefined') {
2478
2494
  try {
2479
2495
  placeholderData = options.select(placeholderData);
2480
- placeholderData = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
2481
2496
  this.selectError = null;
2482
2497
  } catch (selectError) {
2483
2498
  {
@@ -2491,7 +2506,7 @@
2491
2506
 
2492
2507
  if (typeof placeholderData !== 'undefined') {
2493
2508
  status = 'success';
2494
- data = placeholderData;
2509
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
2495
2510
  isPlaceholderData = true;
2496
2511
  }
2497
2512
  }
@@ -2518,6 +2533,7 @@
2518
2533
  error,
2519
2534
  errorUpdatedAt,
2520
2535
  failureCount: state.fetchFailureCount,
2536
+ failureReason: state.fetchFailureReason,
2521
2537
  errorUpdateCount: state.errorUpdateCount,
2522
2538
  isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
2523
2539
  isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,