@tanstack/react-query-devtools 5.0.0-alpha.21 → 5.0.0-alpha.24

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 (58) hide show
  1. package/build/lib/CachePanel/ActiveQuery.d.ts +1 -0
  2. package/build/lib/CachePanel/ActiveQuery.d.ts.map +1 -0
  3. package/build/lib/CachePanel/ActiveQuery.esm.js +7 -1
  4. package/build/lib/CachePanel/ActiveQuery.esm.js.map +1 -1
  5. package/build/lib/CachePanel/ActiveQuery.js +7 -1
  6. package/build/lib/CachePanel/ActiveQuery.js.map +1 -1
  7. package/build/lib/CachePanel/ActiveQuery.mjs +5 -1
  8. package/build/lib/CachePanel/ActiveQuery.mjs.map +1 -1
  9. package/build/lib/CachePanel/CachePanel.d.ts +1 -0
  10. package/build/lib/CachePanel/CachePanel.d.ts.map +1 -0
  11. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +1 -0
  12. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts.map +1 -0
  13. package/build/lib/CachePanel/QueryRow.d.ts +1 -0
  14. package/build/lib/CachePanel/QueryRow.d.ts.map +1 -0
  15. package/build/lib/Explorer.d.ts +1 -0
  16. package/build/lib/Explorer.d.ts.map +1 -0
  17. package/build/lib/Logo.d.ts +1 -0
  18. package/build/lib/Logo.d.ts.map +1 -0
  19. package/build/lib/__tests__/Explorer.test.d.ts +1 -0
  20. package/build/lib/__tests__/Explorer.test.d.ts.map +1 -0
  21. package/build/lib/__tests__/devtools.test.d.ts +1 -0
  22. package/build/lib/__tests__/devtools.test.d.ts.map +1 -0
  23. package/build/lib/__tests__/utils.d.ts +1 -0
  24. package/build/lib/__tests__/utils.d.ts.map +1 -0
  25. package/build/lib/devtools.d.ts +1 -0
  26. package/build/lib/devtools.d.ts.map +1 -0
  27. package/build/lib/index.d.ts +1 -0
  28. package/build/lib/index.d.ts.map +1 -0
  29. package/build/lib/index.prod.d.ts +1 -0
  30. package/build/lib/index.prod.esm.js +7 -1
  31. package/build/lib/index.prod.esm.js.map +1 -1
  32. package/build/lib/index.prod.js +7 -1
  33. package/build/lib/index.prod.js.map +1 -1
  34. package/build/lib/index.prod.mjs +5 -1
  35. package/build/lib/index.prod.mjs.map +1 -1
  36. package/build/lib/noop.d.ts +1 -0
  37. package/build/lib/noop.d.ts.map +1 -0
  38. package/build/lib/screenreader.d.ts +1 -0
  39. package/build/lib/screenreader.d.ts.map +1 -0
  40. package/build/lib/styledComponents.d.ts +1 -0
  41. package/build/lib/styledComponents.d.ts.map +1 -0
  42. package/build/lib/theme.d.ts +1 -0
  43. package/build/lib/theme.d.ts.map +1 -0
  44. package/build/lib/types.d.ts +1 -0
  45. package/build/lib/types.d.ts.map +1 -0
  46. package/build/lib/useLocalStorage.d.ts +1 -0
  47. package/build/lib/useLocalStorage.d.ts.map +1 -0
  48. package/build/lib/useMediaQuery.d.ts +1 -0
  49. package/build/lib/useMediaQuery.d.ts.map +1 -0
  50. package/build/lib/useSubscribeToQueryCache.d.ts +1 -0
  51. package/build/lib/useSubscribeToQueryCache.d.ts.map +1 -0
  52. package/build/lib/utils.d.ts +1 -0
  53. package/build/lib/utils.d.ts.map +1 -0
  54. package/build/umd/index.development.js +5 -1
  55. package/build/umd/index.development.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/CachePanel/ActiveQuery.tsx +9 -1
  58. package/src/__tests__/devtools.test.tsx +55 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-devtools",
3
- "version": "5.0.0-alpha.21",
3
+ "version": "5.0.0-alpha.24",
4
4
  "description": "Developer tools to interact with and visualize the TanStack/react-query cache",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "react": "^18.2.0",
44
44
  "react-dom": "^18.2.0",
45
45
  "react-error-boundary": "^3.1.4",
46
- "@tanstack/react-query": "5.0.0-alpha.21"
46
+ "@tanstack/react-query": "5.0.0-alpha.24"
47
47
  },
48
48
  "dependencies": {
49
49
  "@tanstack/match-sorter-utils": "^8.7.0",
@@ -52,7 +52,7 @@
52
52
  "peerDependencies": {
53
53
  "react": "^18.0.0",
54
54
  "react-dom": "^18.0.0",
55
- "@tanstack/react-query": "5.0.0-alpha.21"
55
+ "@tanstack/react-query": "5.0.0-alpha.24"
56
56
  },
57
57
  "scripts": {
58
58
  "clean": "rimraf ./build",
@@ -101,7 +101,7 @@ const ActiveQuery = ({
101
101
 
102
102
  const restoreQueryAfterLoadingOrError = () => {
103
103
  activeQuery.fetch(
104
- (activeQuery.state.fetchMeta as any).__previousQueryOptions,
104
+ (activeQuery.state.fetchMeta as any)?.__previousQueryOptions,
105
105
  {
106
106
  // Make sure this fetch will cancel the previous one
107
107
  cancelRefetch: true,
@@ -252,6 +252,14 @@ const ActiveQuery = ({
252
252
  <Button
253
253
  type="button"
254
254
  onClick={() => {
255
+ // Return early if the query is already restoring
256
+ if (
257
+ activeQuery.state.fetchStatus === 'fetching' &&
258
+ typeof (activeQuery.state.fetchMeta as any)
259
+ ?.__previousQueryOptions === 'undefined'
260
+ ) {
261
+ return
262
+ }
255
263
  if (activeQuery.state.data === undefined) {
256
264
  restoreQueryAfterLoadingOrError()
257
265
  } else {
@@ -1081,4 +1081,59 @@ describe('ReactQueryDevtools', () => {
1081
1081
  expect(screen.getByText('No error, success')).toBeInTheDocument()
1082
1082
  })
1083
1083
  })
1084
+
1085
+ it('should not refetch when already restoring a query', async () => {
1086
+ const { queryClient } = createQueryClient()
1087
+
1088
+ let count = 0
1089
+ let resolvePromise: (value: unknown) => void = () => undefined
1090
+
1091
+ function App() {
1092
+ const { data } = useQuery({
1093
+ queryKey: ['key'],
1094
+ queryFn: () => {
1095
+ count++
1096
+
1097
+ // Resolve the promise immediately when
1098
+ // the query is fetched for the first time
1099
+ if (count === 1) {
1100
+ return Promise.resolve('test')
1101
+ }
1102
+
1103
+ return new Promise((resolve) => {
1104
+ // Do not resolve immediately and store the
1105
+ // resolve function to resolve the promise later
1106
+ resolvePromise = resolve
1107
+ })
1108
+ },
1109
+ })
1110
+
1111
+ return (
1112
+ <div>
1113
+ <h1>{typeof data === 'string' ? data : 'No data'}</h1>
1114
+ </div>
1115
+ )
1116
+ }
1117
+
1118
+ renderWithClient(queryClient, <App />, {
1119
+ initialIsOpen: true,
1120
+ })
1121
+
1122
+ const loadingButton = await screen.findByRole('button', {
1123
+ name: 'Trigger loading',
1124
+ })
1125
+ fireEvent.click(loadingButton)
1126
+
1127
+ await waitFor(() => {
1128
+ expect(screen.getByText('Restore loading')).toBeInTheDocument()
1129
+ })
1130
+
1131
+ // Click the restore loading button twice and only resolve query promise
1132
+ // after the second click.
1133
+ fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1134
+ fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1135
+ resolvePromise('test')
1136
+
1137
+ expect(count).toBe(2)
1138
+ })
1084
1139
  })