@tanstack/react-query-devtools 4.26.0 → 4.27.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.
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { useMemo } from 'react';
2
3
  import { useQueryClient, onlineManager, notifyManager } from '@tanstack/react-query';
3
4
  import { rankItem } from '@tanstack/match-sorter-utils';
4
5
  import SuperJSON from 'superjson';
@@ -341,7 +342,9 @@ const Button = styled('button', (props, theme) => ({
341
342
  cursor: 'pointer'
342
343
  }));
343
344
  const QueryKeys = styled('span', {
344
- display: 'inline-block',
345
+ display: 'flex',
346
+ flexWrap: 'wrap',
347
+ gap: '0.5em',
345
348
  fontSize: '0.9em'
346
349
  });
347
350
  const QueryKey = styled('span', {
@@ -695,7 +698,8 @@ function ReactQueryDevtools$1({
695
698
  containerElement: Container = 'aside',
696
699
  context,
697
700
  styleNonce,
698
- panelPosition: initialPanelPosition = 'bottom'
701
+ panelPosition: initialPanelPosition = 'bottom',
702
+ errorTypes = []
699
703
  }) {
700
704
  const rootRef = React.useRef(null);
701
705
  const panelRef = React.useRef(null);
@@ -874,7 +878,8 @@ function ReactQueryDevtools$1({
874
878
  style: style,
875
879
  isOpen: isResolvedOpen,
876
880
  setIsOpen: setIsOpen,
877
- onDragStart: e => handleDragStart(panelRef.current, e)
881
+ onDragStart: e => handleDragStart(panelRef.current, e),
882
+ errorTypes: errorTypes
878
883
  }))), !isResolvedOpen ? /*#__PURE__*/React.createElement("button", _extends({
879
884
  type: "button"
880
885
  }, otherToggleButtonProps, {
@@ -939,6 +944,7 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
939
944
  showCloseButton,
940
945
  position,
941
946
  closeButtonProps = {},
947
+ errorTypes = [],
942
948
  ...panelProps
943
949
  } = props;
944
950
  const {
@@ -1057,7 +1063,9 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1057
1063
  }, "Bottom")) : null), /*#__PURE__*/React.createElement("div", {
1058
1064
  style: {
1059
1065
  display: 'flex',
1060
- alignItems: 'center'
1066
+ alignItems: 'center',
1067
+ flexWrap: 'wrap',
1068
+ gap: '0.5em'
1061
1069
  }
1062
1070
  }, /*#__PURE__*/React.createElement(Input, {
1063
1071
  placeholder: "Filter",
@@ -1069,7 +1077,6 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1069
1077
  },
1070
1078
  style: {
1071
1079
  flex: '1',
1072
- marginRight: '.5em',
1073
1080
  width: '100%'
1074
1081
  }
1075
1082
  }), /*#__PURE__*/React.createElement(Select, {
@@ -1169,7 +1176,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1169
1176
  }))), activeQueryHash && isOpen ? /*#__PURE__*/React.createElement(ActiveQuery, {
1170
1177
  activeQueryHash: activeQueryHash,
1171
1178
  queryCache: queryCache,
1172
- queryClient: queryClient
1179
+ queryClient: queryClient,
1180
+ errorTypes: errorTypes
1173
1181
  }) : null, showCloseButton ? /*#__PURE__*/React.createElement(Button, _extends({
1174
1182
  type: "button",
1175
1183
  "aria-controls": "ReactQueryDevtoolsPanel",
@@ -1194,7 +1202,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1194
1202
  const ActiveQuery = ({
1195
1203
  queryCache,
1196
1204
  activeQueryHash,
1197
- queryClient
1205
+ queryClient,
1206
+ errorTypes
1198
1207
  }) => {
1199
1208
  var _useSubscribeToQueryC, _useSubscribeToQueryC2;
1200
1209
 
@@ -1220,10 +1229,44 @@ const ActiveQuery = ({
1220
1229
  promise == null ? void 0 : promise.catch(noop);
1221
1230
  };
1222
1231
 
1232
+ const currentErrorTypeName = useMemo(() => {
1233
+ if (activeQuery && activeQueryState != null && activeQueryState.error) {
1234
+ const errorType = errorTypes.find(type => {
1235
+ var _activeQueryState$err;
1236
+
1237
+ return type.initializer(activeQuery).toString() === ((_activeQueryState$err = activeQueryState.error) == null ? void 0 : _activeQueryState$err.toString());
1238
+ });
1239
+ return errorType == null ? void 0 : errorType.name;
1240
+ }
1241
+
1242
+ return undefined;
1243
+ }, [activeQuery, activeQueryState == null ? void 0 : activeQueryState.error, errorTypes]);
1244
+
1223
1245
  if (!activeQuery || !activeQueryState) {
1224
1246
  return null;
1225
1247
  }
1226
1248
 
1249
+ const triggerError = errorType => {
1250
+ var _errorType$initialize;
1251
+
1252
+ const error = (_errorType$initialize = errorType == null ? void 0 : errorType.initializer(activeQuery)) != null ? _errorType$initialize : new Error('Unknown error from devtools');
1253
+ const __previousQueryOptions = activeQuery.options;
1254
+ activeQuery.setState({
1255
+ status: 'error',
1256
+ error,
1257
+ fetchMeta: { ...activeQuery.state.fetchMeta,
1258
+ __previousQueryOptions
1259
+ }
1260
+ });
1261
+ };
1262
+
1263
+ const restoreQueryAfterLoadingOrError = () => {
1264
+ activeQuery.fetch(activeQuery.state.fetchMeta.__previousQueryOptions, {
1265
+ // Make sure this fetch will cancel the previous one
1266
+ cancelRefetch: true
1267
+ });
1268
+ };
1269
+
1227
1270
  return /*#__PURE__*/React.createElement(ActiveQueryPanel, null, /*#__PURE__*/React.createElement("div", {
1228
1271
  style: {
1229
1272
  padding: '.5em',
@@ -1290,7 +1333,11 @@ const ActiveQuery = ({
1290
1333
  }
1291
1334
  }, "Actions"), /*#__PURE__*/React.createElement("div", {
1292
1335
  style: {
1293
- padding: '0.5em'
1336
+ padding: '0.5em',
1337
+ display: 'flex',
1338
+ flexWrap: 'wrap',
1339
+ gap: '0.5em',
1340
+ alignItems: 'flex-end'
1294
1341
  }
1295
1342
  }, /*#__PURE__*/React.createElement(Button, {
1296
1343
  type: "button",
@@ -1318,7 +1365,61 @@ const ActiveQuery = ({
1318
1365
  style: {
1319
1366
  background: defaultTheme.danger
1320
1367
  }
1321
- }, "Remove")), /*#__PURE__*/React.createElement("div", {
1368
+ }, "Remove"), ' ', /*#__PURE__*/React.createElement(Button, {
1369
+ type: "button",
1370
+ onClick: () => {
1371
+ if (activeQuery.state.data === undefined) {
1372
+ restoreQueryAfterLoadingOrError();
1373
+ } else {
1374
+ const __previousQueryOptions = activeQuery.options; // Trigger a fetch in order to trigger suspense as well.
1375
+
1376
+ activeQuery.fetch({ ...__previousQueryOptions,
1377
+ queryFn: () => {
1378
+ return new Promise(() => {// Never resolve
1379
+ });
1380
+ },
1381
+ cacheTime: -1
1382
+ });
1383
+ activeQuery.setState({
1384
+ data: undefined,
1385
+ status: 'loading',
1386
+ fetchMeta: { ...activeQuery.state.fetchMeta,
1387
+ __previousQueryOptions
1388
+ }
1389
+ });
1390
+ }
1391
+ },
1392
+ style: {
1393
+ background: defaultTheme.paused
1394
+ }
1395
+ }, activeQuery.state.status === 'loading' ? 'Restore' : 'Trigger', ' ', "loading"), ' ', errorTypes.length === 0 || activeQuery.state.status === 'error' ? /*#__PURE__*/React.createElement(Button, {
1396
+ type: "button",
1397
+ onClick: () => {
1398
+ if (!activeQuery.state.error) {
1399
+ triggerError();
1400
+ } else {
1401
+ queryClient.resetQueries(activeQuery);
1402
+ }
1403
+ },
1404
+ style: {
1405
+ background: defaultTheme.danger
1406
+ }
1407
+ }, activeQuery.state.status === 'error' ? 'Restore' : 'Trigger', " error") : /*#__PURE__*/React.createElement("label", null, "Trigger error:", /*#__PURE__*/React.createElement(Select, {
1408
+ value: currentErrorTypeName != null ? currentErrorTypeName : '',
1409
+ style: {
1410
+ marginInlineStart: '.5em'
1411
+ },
1412
+ onChange: e => {
1413
+ const errorType = errorTypes.find(t => t.name === e.target.value);
1414
+ triggerError(errorType);
1415
+ }
1416
+ }, /*#__PURE__*/React.createElement("option", {
1417
+ key: "",
1418
+ value: ""
1419
+ }), errorTypes.map(errorType => /*#__PURE__*/React.createElement("option", {
1420
+ key: errorType.name,
1421
+ value: errorType.name
1422
+ }, errorType.name))))), /*#__PURE__*/React.createElement("div", {
1322
1423
  style: {
1323
1424
  background: defaultTheme.backgroundAlt,
1324
1425
  padding: '.5em',