@tanstack/react-query-devtools 5.0.0-alpha.1 → 5.0.0-alpha.10

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.
Files changed (47) hide show
  1. package/build/lib/Explorer.esm.js +2 -1
  2. package/build/lib/Explorer.esm.js.map +1 -1
  3. package/build/lib/Explorer.js +2 -1
  4. package/build/lib/Explorer.js.map +1 -1
  5. package/build/lib/Explorer.mjs +1 -0
  6. package/build/lib/Explorer.mjs.map +1 -1
  7. package/build/lib/devtools.d.ts +20 -2
  8. package/build/lib/devtools.esm.js +161 -34
  9. package/build/lib/devtools.esm.js.map +1 -1
  10. package/build/lib/devtools.js +160 -34
  11. package/build/lib/devtools.js.map +1 -1
  12. package/build/lib/devtools.mjs +105 -9
  13. package/build/lib/devtools.mjs.map +1 -1
  14. package/build/lib/index.esm.js +1 -0
  15. package/build/lib/index.esm.js.map +1 -1
  16. package/build/lib/index.js +1 -0
  17. package/build/lib/index.js.map +1 -1
  18. package/build/lib/index.mjs +1 -0
  19. package/build/lib/index.mjs.map +1 -1
  20. package/build/lib/index.prod.esm.js +164 -36
  21. package/build/lib/index.prod.esm.js.map +1 -1
  22. package/build/lib/index.prod.js +163 -36
  23. package/build/lib/index.prod.js.map +1 -1
  24. package/build/lib/index.prod.mjs +107 -10
  25. package/build/lib/index.prod.mjs.map +1 -1
  26. package/build/lib/styledComponents.d.ts +0 -1
  27. package/build/lib/styledComponents.esm.js +3 -1
  28. package/build/lib/styledComponents.esm.js.map +1 -1
  29. package/build/lib/styledComponents.js +3 -1
  30. package/build/lib/styledComponents.js.map +1 -1
  31. package/build/lib/styledComponents.mjs +3 -1
  32. package/build/lib/styledComponents.mjs.map +1 -1
  33. package/build/lib/theme.esm.js +1 -0
  34. package/build/lib/theme.esm.js.map +1 -1
  35. package/build/lib/theme.js +1 -0
  36. package/build/lib/theme.js.map +1 -1
  37. package/build/lib/theme.mjs +1 -0
  38. package/build/lib/theme.mjs.map +1 -1
  39. package/build/umd/index.development.js +106 -10
  40. package/build/umd/index.development.js.map +1 -1
  41. package/build/umd/index.production.js.map +1 -1
  42. package/package.json +4 -4
  43. package/src/__tests__/Explorer.test.tsx +3 -2
  44. package/src/__tests__/devtools.test.tsx +157 -8
  45. package/src/devtools.tsx +150 -3
  46. package/src/index.ts +2 -0
  47. package/src/styledComponents.ts +3 -1
@@ -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';
@@ -330,7 +331,9 @@ const Button = styled('button', (props, theme) => ({
330
331
  cursor: 'pointer'
331
332
  }));
332
333
  const QueryKeys = styled('span', {
333
- display: 'inline-block',
334
+ display: 'flex',
335
+ flexWrap: 'wrap',
336
+ gap: '0.5em',
334
337
  fontSize: '0.9em'
335
338
  });
336
339
  const QueryKey = styled('span', {
@@ -674,7 +677,8 @@ function ReactQueryDevtools$1({
674
677
  containerElement: Container = 'aside',
675
678
  queryClient,
676
679
  styleNonce,
677
- panelPosition: initialPanelPosition = 'bottom'
680
+ panelPosition: initialPanelPosition = 'bottom',
681
+ errorTypes = []
678
682
  }) {
679
683
  const rootRef = React.useRef(null);
680
684
  const panelRef = React.useRef(null);
@@ -839,7 +843,8 @@ function ReactQueryDevtools$1({
839
843
  style: style,
840
844
  isOpen: isResolvedOpen,
841
845
  setIsOpen: setIsOpen,
842
- onDragStart: e => handleDragStart(panelRef.current, e)
846
+ onDragStart: e => handleDragStart(panelRef.current, e),
847
+ errorTypes: errorTypes
843
848
  }))), !isResolvedOpen ? /*#__PURE__*/React.createElement("button", _extends({
844
849
  type: "button"
845
850
  }, otherToggleButtonProps, {
@@ -902,6 +907,7 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
902
907
  showCloseButton,
903
908
  position,
904
909
  closeButtonProps = {},
910
+ errorTypes = [],
905
911
  ...panelProps
906
912
  } = props;
907
913
  const {
@@ -1035,7 +1041,9 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1035
1041
  }, "Bottom")) : null), /*#__PURE__*/React.createElement("div", {
1036
1042
  style: {
1037
1043
  display: 'flex',
1038
- alignItems: 'center'
1044
+ alignItems: 'center',
1045
+ flexWrap: 'wrap',
1046
+ gap: '0.5em'
1039
1047
  }
1040
1048
  }, /*#__PURE__*/React.createElement(Input, {
1041
1049
  placeholder: "Filter",
@@ -1047,7 +1055,6 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1047
1055
  },
1048
1056
  style: {
1049
1057
  flex: '1',
1050
- marginRight: '.5em',
1051
1058
  width: '100%'
1052
1059
  }
1053
1060
  }), /*#__PURE__*/React.createElement(Select, {
@@ -1147,7 +1154,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1147
1154
  }))), activeQueryHash && isOpen ? /*#__PURE__*/React.createElement(ActiveQuery, {
1148
1155
  activeQueryHash: activeQueryHash,
1149
1156
  queryCache: queryCache,
1150
- queryClient: client
1157
+ queryClient: client,
1158
+ errorTypes: errorTypes
1151
1159
  }) : null, showCloseButton ? /*#__PURE__*/React.createElement(Button, _extends({
1152
1160
  type: "button",
1153
1161
  "aria-controls": "ReactQueryDevtoolsPanel",
@@ -1171,7 +1179,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
1171
1179
  const ActiveQuery = ({
1172
1180
  queryCache,
1173
1181
  activeQueryHash,
1174
- queryClient
1182
+ queryClient,
1183
+ errorTypes
1175
1184
  }) => {
1176
1185
  const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
1177
1186
  const activeQueryState = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.state);
@@ -1181,9 +1190,35 @@ const ActiveQuery = ({
1181
1190
  const promise = activeQuery?.fetch();
1182
1191
  promise?.catch(noop);
1183
1192
  };
1193
+ const currentErrorTypeName = useMemo(() => {
1194
+ if (activeQuery && activeQueryState?.error) {
1195
+ const errorType = errorTypes.find(type => type.initializer(activeQuery).toString() === activeQueryState.error?.toString());
1196
+ return errorType?.name;
1197
+ }
1198
+ return undefined;
1199
+ }, [activeQuery, activeQueryState?.error, errorTypes]);
1184
1200
  if (!activeQuery || !activeQueryState) {
1185
1201
  return null;
1186
1202
  }
1203
+ const triggerError = errorType => {
1204
+ const error = errorType?.initializer(activeQuery) ?? new Error('Unknown error from devtools');
1205
+ const __previousQueryOptions = activeQuery.options;
1206
+ activeQuery.setState({
1207
+ status: 'error',
1208
+ error,
1209
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
1210
+ fetchMeta: {
1211
+ ...activeQuery.state.fetchMeta,
1212
+ __previousQueryOptions
1213
+ }
1214
+ });
1215
+ };
1216
+ const restoreQueryAfterLoadingOrError = () => {
1217
+ activeQuery.fetch(activeQuery.state.fetchMeta.__previousQueryOptions, {
1218
+ // Make sure this fetch will cancel the previous one
1219
+ cancelRefetch: true
1220
+ });
1221
+ };
1187
1222
  return /*#__PURE__*/React.createElement(ActiveQueryPanel, null, /*#__PURE__*/React.createElement("div", {
1188
1223
  style: {
1189
1224
  padding: '.5em',
@@ -1200,7 +1235,7 @@ const ActiveQuery = ({
1200
1235
  style: {
1201
1236
  marginBottom: '.5em',
1202
1237
  display: 'flex',
1203
- alignItems: 'stretch',
1238
+ alignItems: 'flex-start',
1204
1239
  justifyContent: 'space-between'
1205
1240
  }
1206
1241
  }, /*#__PURE__*/React.createElement(Code, {
@@ -1250,7 +1285,11 @@ const ActiveQuery = ({
1250
1285
  }
1251
1286
  }, "Actions"), /*#__PURE__*/React.createElement("div", {
1252
1287
  style: {
1253
- padding: '0.5em'
1288
+ padding: '0.5em',
1289
+ display: 'flex',
1290
+ flexWrap: 'wrap',
1291
+ gap: '0.5em',
1292
+ alignItems: 'flex-end'
1254
1293
  }
1255
1294
  }, /*#__PURE__*/React.createElement(Button, {
1256
1295
  type: "button",
@@ -1278,7 +1317,65 @@ const ActiveQuery = ({
1278
1317
  style: {
1279
1318
  background: defaultTheme.danger
1280
1319
  }
1281
- }, "Remove")), /*#__PURE__*/React.createElement("div", {
1320
+ }, "Remove"), ' ', /*#__PURE__*/React.createElement(Button, {
1321
+ type: "button",
1322
+ onClick: () => {
1323
+ if (activeQuery.state.data === undefined) {
1324
+ restoreQueryAfterLoadingOrError();
1325
+ } else {
1326
+ const __previousQueryOptions = activeQuery.options;
1327
+ // Trigger a fetch in order to trigger suspense as well.
1328
+ activeQuery.fetch({
1329
+ ...__previousQueryOptions,
1330
+ queryFn: () => {
1331
+ return new Promise(() => {
1332
+ // Never resolve
1333
+ });
1334
+ },
1335
+ gcTime: -1
1336
+ });
1337
+ activeQuery.setState({
1338
+ data: undefined,
1339
+ status: 'pending',
1340
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
1341
+ fetchMeta: {
1342
+ ...activeQuery.state.fetchMeta,
1343
+ __previousQueryOptions
1344
+ }
1345
+ });
1346
+ }
1347
+ },
1348
+ style: {
1349
+ background: defaultTheme.paused
1350
+ }
1351
+ }, activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger', ' ', "loading"), ' ', errorTypes.length === 0 || activeQuery.state.status === 'error' ? /*#__PURE__*/React.createElement(Button, {
1352
+ type: "button",
1353
+ onClick: () => {
1354
+ if (!activeQuery.state.error) {
1355
+ triggerError();
1356
+ } else {
1357
+ queryClient.resetQueries(activeQuery);
1358
+ }
1359
+ },
1360
+ style: {
1361
+ background: defaultTheme.danger
1362
+ }
1363
+ }, activeQuery.state.status === 'error' ? 'Restore' : 'Trigger', " error") : /*#__PURE__*/React.createElement("label", null, "Trigger error:", /*#__PURE__*/React.createElement(Select, {
1364
+ value: currentErrorTypeName ?? '',
1365
+ style: {
1366
+ marginInlineStart: '.5em'
1367
+ },
1368
+ onChange: e => {
1369
+ const errorType = errorTypes.find(t => t.name === e.target.value);
1370
+ triggerError(errorType);
1371
+ }
1372
+ }, /*#__PURE__*/React.createElement("option", {
1373
+ key: "",
1374
+ value: ""
1375
+ }), errorTypes.map(errorType => /*#__PURE__*/React.createElement("option", {
1376
+ key: errorType.name,
1377
+ value: errorType.name
1378
+ }, errorType.name))))), /*#__PURE__*/React.createElement("div", {
1282
1379
  style: {
1283
1380
  background: defaultTheme.backgroundAlt,
1284
1381
  padding: '.5em',