@tanstack/react-query 4.10.3 → 4.13.0
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/LICENSE +1 -1
- package/build/umd/index.development.js +27 -10
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -4
- package/src/__tests__/useInfiniteQuery.test.tsx +2 -0
- package/src/__tests__/useMutation.test.tsx +58 -1
- package/src/__tests__/useQuery.test.tsx +51 -45
- package/src/__tests__/utils.tsx +6 -4
package/LICENSE
CHANGED
|
@@ -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:
|
|
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: () => {
|
|
@@ -1500,7 +1509,7 @@
|
|
|
1500
1509
|
variables: this.options.variables
|
|
1501
1510
|
}); // Notify cache callback
|
|
1502
1511
|
|
|
1503
|
-
(_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this);
|
|
1512
|
+
await ((_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this));
|
|
1504
1513
|
const context = await ((_this$options$onMutat = (_this$options = this.options).onMutate) == null ? void 0 : _this$options$onMutat.call(_this$options, this.state.variables));
|
|
1505
1514
|
|
|
1506
1515
|
if (context !== this.state.context) {
|
|
@@ -1514,7 +1523,7 @@
|
|
|
1514
1523
|
|
|
1515
1524
|
const data = await executeMutation(); // Notify cache callback
|
|
1516
1525
|
|
|
1517
|
-
(_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);
|
|
1526
|
+
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));
|
|
1518
1527
|
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));
|
|
1519
1528
|
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));
|
|
1520
1529
|
this.dispatch({
|
|
@@ -1527,7 +1536,7 @@
|
|
|
1527
1536
|
var _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onError, _this$options4, _this$options$onSettl2, _this$options5;
|
|
1528
1537
|
|
|
1529
1538
|
// Notify cache callback
|
|
1530
|
-
(_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);
|
|
1539
|
+
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));
|
|
1531
1540
|
|
|
1532
1541
|
if ("development" !== 'production') {
|
|
1533
1542
|
this.logger.error(error);
|
|
@@ -1550,7 +1559,8 @@
|
|
|
1550
1559
|
switch (action.type) {
|
|
1551
1560
|
case 'failed':
|
|
1552
1561
|
return { ...state,
|
|
1553
|
-
failureCount:
|
|
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
|
|
@@ -2518,6 +2534,7 @@
|
|
|
2518
2534
|
error,
|
|
2519
2535
|
errorUpdatedAt,
|
|
2520
2536
|
failureCount: state.fetchFailureCount,
|
|
2537
|
+
failureReason: state.fetchFailureReason,
|
|
2521
2538
|
errorUpdateCount: state.errorUpdateCount,
|
|
2522
2539
|
isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
|
|
2523
2540
|
isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
|