@tanstack/react-query-devtools 5.0.0-alpha.1 → 5.0.0-alpha.11
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/build/lib/Explorer.esm.js +2 -1
- package/build/lib/Explorer.esm.js.map +1 -1
- package/build/lib/Explorer.js +2 -1
- package/build/lib/Explorer.js.map +1 -1
- package/build/lib/Explorer.mjs +1 -0
- package/build/lib/Explorer.mjs.map +1 -1
- package/build/lib/devtools.d.ts +20 -2
- package/build/lib/devtools.esm.js +162 -34
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +161 -34
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +106 -9
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.esm.js +1 -0
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -0
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/index.prod.esm.js +165 -36
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +164 -36
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +108 -10
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/lib/styledComponents.d.ts +0 -1
- package/build/lib/styledComponents.esm.js +3 -1
- package/build/lib/styledComponents.esm.js.map +1 -1
- package/build/lib/styledComponents.js +3 -1
- package/build/lib/styledComponents.js.map +1 -1
- package/build/lib/styledComponents.mjs +3 -1
- package/build/lib/styledComponents.mjs.map +1 -1
- package/build/lib/theme.esm.js +1 -0
- package/build/lib/theme.esm.js.map +1 -1
- package/build/lib/theme.js +1 -0
- package/build/lib/theme.js.map +1 -1
- package/build/lib/theme.mjs +1 -0
- package/build/lib/theme.mjs.map +1 -1
- package/build/umd/index.development.js +107 -10
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/Explorer.test.tsx +3 -2
- package/src/__tests__/devtools.test.tsx +183 -9
- package/src/devtools.tsx +151 -3
- package/src/index.ts +2 -0
- package/src/styledComponents.ts +3 -1
package/build/lib/index.prod.mjs
CHANGED
|
@@ -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: '
|
|
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, {
|
|
@@ -1079,6 +1086,7 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
|
|
|
1079
1086
|
} else {
|
|
1080
1087
|
onlineManager.setOnline(false);
|
|
1081
1088
|
setMockOffline(true);
|
|
1089
|
+
window.dispatchEvent(new Event('offline'));
|
|
1082
1090
|
}
|
|
1083
1091
|
},
|
|
1084
1092
|
"aria-label": isMockOffline ? 'Restore offline mock' : 'Mock offline behavior',
|
|
@@ -1147,7 +1155,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
|
|
|
1147
1155
|
}))), activeQueryHash && isOpen ? /*#__PURE__*/React.createElement(ActiveQuery, {
|
|
1148
1156
|
activeQueryHash: activeQueryHash,
|
|
1149
1157
|
queryCache: queryCache,
|
|
1150
|
-
queryClient: client
|
|
1158
|
+
queryClient: client,
|
|
1159
|
+
errorTypes: errorTypes
|
|
1151
1160
|
}) : null, showCloseButton ? /*#__PURE__*/React.createElement(Button, _extends({
|
|
1152
1161
|
type: "button",
|
|
1153
1162
|
"aria-controls": "ReactQueryDevtoolsPanel",
|
|
@@ -1171,7 +1180,8 @@ const ReactQueryDevtoolsPanel$1 = /*#__PURE__*/React.forwardRef(function ReactQu
|
|
|
1171
1180
|
const ActiveQuery = ({
|
|
1172
1181
|
queryCache,
|
|
1173
1182
|
activeQueryHash,
|
|
1174
|
-
queryClient
|
|
1183
|
+
queryClient,
|
|
1184
|
+
errorTypes
|
|
1175
1185
|
}) => {
|
|
1176
1186
|
const activeQuery = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash));
|
|
1177
1187
|
const activeQueryState = useSubscribeToQueryCache(queryCache, () => queryCache.getAll().find(query => query.queryHash === activeQueryHash)?.state);
|
|
@@ -1181,9 +1191,35 @@ const ActiveQuery = ({
|
|
|
1181
1191
|
const promise = activeQuery?.fetch();
|
|
1182
1192
|
promise?.catch(noop);
|
|
1183
1193
|
};
|
|
1194
|
+
const currentErrorTypeName = useMemo(() => {
|
|
1195
|
+
if (activeQuery && activeQueryState?.error) {
|
|
1196
|
+
const errorType = errorTypes.find(type => type.initializer(activeQuery).toString() === activeQueryState.error?.toString());
|
|
1197
|
+
return errorType?.name;
|
|
1198
|
+
}
|
|
1199
|
+
return undefined;
|
|
1200
|
+
}, [activeQuery, activeQueryState?.error, errorTypes]);
|
|
1184
1201
|
if (!activeQuery || !activeQueryState) {
|
|
1185
1202
|
return null;
|
|
1186
1203
|
}
|
|
1204
|
+
const triggerError = errorType => {
|
|
1205
|
+
const error = errorType?.initializer(activeQuery) ?? new Error('Unknown error from devtools');
|
|
1206
|
+
const __previousQueryOptions = activeQuery.options;
|
|
1207
|
+
activeQuery.setState({
|
|
1208
|
+
status: 'error',
|
|
1209
|
+
error,
|
|
1210
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
1211
|
+
fetchMeta: {
|
|
1212
|
+
...activeQuery.state.fetchMeta,
|
|
1213
|
+
__previousQueryOptions
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
};
|
|
1217
|
+
const restoreQueryAfterLoadingOrError = () => {
|
|
1218
|
+
activeQuery.fetch(activeQuery.state.fetchMeta.__previousQueryOptions, {
|
|
1219
|
+
// Make sure this fetch will cancel the previous one
|
|
1220
|
+
cancelRefetch: true
|
|
1221
|
+
});
|
|
1222
|
+
};
|
|
1187
1223
|
return /*#__PURE__*/React.createElement(ActiveQueryPanel, null, /*#__PURE__*/React.createElement("div", {
|
|
1188
1224
|
style: {
|
|
1189
1225
|
padding: '.5em',
|
|
@@ -1200,7 +1236,7 @@ const ActiveQuery = ({
|
|
|
1200
1236
|
style: {
|
|
1201
1237
|
marginBottom: '.5em',
|
|
1202
1238
|
display: 'flex',
|
|
1203
|
-
alignItems: '
|
|
1239
|
+
alignItems: 'flex-start',
|
|
1204
1240
|
justifyContent: 'space-between'
|
|
1205
1241
|
}
|
|
1206
1242
|
}, /*#__PURE__*/React.createElement(Code, {
|
|
@@ -1250,7 +1286,11 @@ const ActiveQuery = ({
|
|
|
1250
1286
|
}
|
|
1251
1287
|
}, "Actions"), /*#__PURE__*/React.createElement("div", {
|
|
1252
1288
|
style: {
|
|
1253
|
-
padding: '0.5em'
|
|
1289
|
+
padding: '0.5em',
|
|
1290
|
+
display: 'flex',
|
|
1291
|
+
flexWrap: 'wrap',
|
|
1292
|
+
gap: '0.5em',
|
|
1293
|
+
alignItems: 'flex-end'
|
|
1254
1294
|
}
|
|
1255
1295
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
1256
1296
|
type: "button",
|
|
@@ -1278,7 +1318,65 @@ const ActiveQuery = ({
|
|
|
1278
1318
|
style: {
|
|
1279
1319
|
background: defaultTheme.danger
|
|
1280
1320
|
}
|
|
1281
|
-
}, "Remove")
|
|
1321
|
+
}, "Remove"), ' ', /*#__PURE__*/React.createElement(Button, {
|
|
1322
|
+
type: "button",
|
|
1323
|
+
onClick: () => {
|
|
1324
|
+
if (activeQuery.state.data === undefined) {
|
|
1325
|
+
restoreQueryAfterLoadingOrError();
|
|
1326
|
+
} else {
|
|
1327
|
+
const __previousQueryOptions = activeQuery.options;
|
|
1328
|
+
// Trigger a fetch in order to trigger suspense as well.
|
|
1329
|
+
activeQuery.fetch({
|
|
1330
|
+
...__previousQueryOptions,
|
|
1331
|
+
queryFn: () => {
|
|
1332
|
+
return new Promise(() => {
|
|
1333
|
+
// Never resolve
|
|
1334
|
+
});
|
|
1335
|
+
},
|
|
1336
|
+
gcTime: -1
|
|
1337
|
+
});
|
|
1338
|
+
activeQuery.setState({
|
|
1339
|
+
data: undefined,
|
|
1340
|
+
status: 'pending',
|
|
1341
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
1342
|
+
fetchMeta: {
|
|
1343
|
+
...activeQuery.state.fetchMeta,
|
|
1344
|
+
__previousQueryOptions
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
},
|
|
1349
|
+
style: {
|
|
1350
|
+
background: defaultTheme.paused
|
|
1351
|
+
}
|
|
1352
|
+
}, activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger', ' ', "loading"), ' ', errorTypes.length === 0 || activeQuery.state.status === 'error' ? /*#__PURE__*/React.createElement(Button, {
|
|
1353
|
+
type: "button",
|
|
1354
|
+
onClick: () => {
|
|
1355
|
+
if (!activeQuery.state.error) {
|
|
1356
|
+
triggerError();
|
|
1357
|
+
} else {
|
|
1358
|
+
queryClient.resetQueries(activeQuery);
|
|
1359
|
+
}
|
|
1360
|
+
},
|
|
1361
|
+
style: {
|
|
1362
|
+
background: defaultTheme.danger
|
|
1363
|
+
}
|
|
1364
|
+
}, activeQuery.state.status === 'error' ? 'Restore' : 'Trigger', " error") : /*#__PURE__*/React.createElement("label", null, "Trigger error:", /*#__PURE__*/React.createElement(Select, {
|
|
1365
|
+
value: currentErrorTypeName ?? '',
|
|
1366
|
+
style: {
|
|
1367
|
+
marginInlineStart: '.5em'
|
|
1368
|
+
},
|
|
1369
|
+
onChange: e => {
|
|
1370
|
+
const errorType = errorTypes.find(t => t.name === e.target.value);
|
|
1371
|
+
triggerError(errorType);
|
|
1372
|
+
}
|
|
1373
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
1374
|
+
key: "",
|
|
1375
|
+
value: ""
|
|
1376
|
+
}), errorTypes.map(errorType => /*#__PURE__*/React.createElement("option", {
|
|
1377
|
+
key: errorType.name,
|
|
1378
|
+
value: errorType.name
|
|
1379
|
+
}, errorType.name))))), /*#__PURE__*/React.createElement("div", {
|
|
1282
1380
|
style: {
|
|
1283
1381
|
background: defaultTheme.backgroundAlt,
|
|
1284
1382
|
padding: '.5em',
|