@tanstack/react-query-devtools 5.0.0-alpha.26 → 5.0.0-alpha.27

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 (159) hide show
  1. package/build/lib/__tests__/devtools.test.d.ts +0 -1
  2. package/build/lib/__tests__/devtools.test.d.ts.map +1 -1
  3. package/build/lib/devtools.d.ts +8 -30
  4. package/build/lib/devtools.d.ts.map +1 -1
  5. package/build/lib/devtools.esm.js +47 -226
  6. package/build/lib/devtools.esm.js.map +1 -1
  7. package/build/lib/devtools.js +45 -244
  8. package/build/lib/devtools.js.map +1 -1
  9. package/build/lib/devtools.mjs +47 -225
  10. package/build/lib/devtools.mjs.map +1 -1
  11. package/build/lib/index.d.ts +0 -1
  12. package/build/lib/index.d.ts.map +1 -1
  13. package/build/lib/index.esm.js +8 -5
  14. package/build/lib/index.esm.js.map +1 -1
  15. package/build/lib/index.js +7 -5
  16. package/build/lib/index.js.map +1 -1
  17. package/build/lib/index.mjs +8 -5
  18. package/build/lib/index.mjs.map +1 -1
  19. package/build/lib/index.prod.d.ts +0 -1
  20. package/build/lib/index.prod.esm.js +7901 -1501
  21. package/build/lib/index.prod.esm.js.map +1 -1
  22. package/build/lib/index.prod.js +7909 -1528
  23. package/build/lib/index.prod.js.map +1 -1
  24. package/build/lib/index.prod.mjs +7922 -1489
  25. package/build/lib/index.prod.mjs.map +1 -1
  26. package/build/umd/index.development.js +7146 -2375
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +2 -3
  31. package/src/__tests__/devtools.test.tsx +1 -1135
  32. package/src/devtools.tsx +52 -306
  33. package/src/index.ts +6 -6
  34. package/build/lib/CachePanel/ActiveQuery.d.ts +0 -19
  35. package/build/lib/CachePanel/ActiveQuery.d.ts.map +0 -1
  36. package/build/lib/CachePanel/ActiveQuery.esm.js +0 -277
  37. package/build/lib/CachePanel/ActiveQuery.esm.js.map +0 -1
  38. package/build/lib/CachePanel/ActiveQuery.js +0 -281
  39. package/build/lib/CachePanel/ActiveQuery.js.map +0 -1
  40. package/build/lib/CachePanel/ActiveQuery.mjs +0 -261
  41. package/build/lib/CachePanel/ActiveQuery.mjs.map +0 -1
  42. package/build/lib/CachePanel/CachePanel.d.ts +0 -58
  43. package/build/lib/CachePanel/CachePanel.d.ts.map +0 -1
  44. package/build/lib/CachePanel/CachePanel.esm.js +0 -310
  45. package/build/lib/CachePanel/CachePanel.esm.js.map +0 -1
  46. package/build/lib/CachePanel/CachePanel.js +0 -315
  47. package/build/lib/CachePanel/CachePanel.js.map +0 -1
  48. package/build/lib/CachePanel/CachePanel.mjs +0 -310
  49. package/build/lib/CachePanel/CachePanel.mjs.map +0 -1
  50. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts +0 -8
  51. package/build/lib/CachePanel/Header/QueryStatusCount.d.ts.map +0 -1
  52. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js +0 -49
  53. package/build/lib/CachePanel/Header/QueryStatusCount.esm.js.map +0 -1
  54. package/build/lib/CachePanel/Header/QueryStatusCount.js +0 -53
  55. package/build/lib/CachePanel/Header/QueryStatusCount.js.map +0 -1
  56. package/build/lib/CachePanel/Header/QueryStatusCount.mjs +0 -49
  57. package/build/lib/CachePanel/Header/QueryStatusCount.mjs.map +0 -1
  58. package/build/lib/CachePanel/QueryRow.d.ts +0 -14
  59. package/build/lib/CachePanel/QueryRow.d.ts.map +0 -1
  60. package/build/lib/CachePanel/QueryRow.esm.js +0 -98
  61. package/build/lib/CachePanel/QueryRow.esm.js.map +0 -1
  62. package/build/lib/CachePanel/QueryRow.js +0 -102
  63. package/build/lib/CachePanel/QueryRow.js.map +0 -1
  64. package/build/lib/CachePanel/QueryRow.mjs +0 -82
  65. package/build/lib/CachePanel/QueryRow.mjs.map +0 -1
  66. package/build/lib/Explorer.d.ts +0 -51
  67. package/build/lib/Explorer.d.ts.map +0 -1
  68. package/build/lib/Explorer.esm.js +0 -254
  69. package/build/lib/Explorer.esm.js.map +0 -1
  70. package/build/lib/Explorer.js +0 -288
  71. package/build/lib/Explorer.js.map +0 -1
  72. package/build/lib/Explorer.mjs +0 -254
  73. package/build/lib/Explorer.mjs.map +0 -1
  74. package/build/lib/Logo.d.ts +0 -2
  75. package/build/lib/Logo.esm.js +0 -32
  76. package/build/lib/Logo.esm.js.map +0 -1
  77. package/build/lib/Logo.js +0 -55
  78. package/build/lib/Logo.js.map +0 -1
  79. package/build/lib/Logo.mjs +0 -32
  80. package/build/lib/Logo.mjs.map +0 -1
  81. package/build/lib/__tests__/Explorer.test.d.ts +0 -2
  82. package/build/lib/__tests__/Explorer.test.d.ts.map +0 -1
  83. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -17
  84. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  85. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -19
  86. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  87. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -17
  88. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +0 -1
  89. package/build/lib/noop.d.ts +0 -3
  90. package/build/lib/screenreader.d.ts +0 -4
  91. package/build/lib/screenreader.esm.js +0 -17
  92. package/build/lib/screenreader.esm.js.map +0 -1
  93. package/build/lib/screenreader.js +0 -40
  94. package/build/lib/screenreader.js.map +0 -1
  95. package/build/lib/screenreader.mjs +0 -17
  96. package/build/lib/screenreader.mjs.map +0 -1
  97. package/build/lib/styledComponents.d.ts +0 -9
  98. package/build/lib/styledComponents.d.ts.map +0 -1
  99. package/build/lib/styledComponents.esm.js +0 -103
  100. package/build/lib/styledComponents.esm.js.map +0 -1
  101. package/build/lib/styledComponents.js +0 -112
  102. package/build/lib/styledComponents.js.map +0 -1
  103. package/build/lib/styledComponents.mjs +0 -103
  104. package/build/lib/styledComponents.mjs.map +0 -1
  105. package/build/lib/theme.d.ts +0 -37
  106. package/build/lib/theme.esm.js +0 -33
  107. package/build/lib/theme.esm.js.map +0 -1
  108. package/build/lib/theme.js +0 -56
  109. package/build/lib/theme.js.map +0 -1
  110. package/build/lib/theme.mjs +0 -33
  111. package/build/lib/theme.mjs.map +0 -1
  112. package/build/lib/types.d.ts +0 -12
  113. package/build/lib/types.d.ts.map +0 -1
  114. package/build/lib/useLocalStorage.d.ts +0 -2
  115. package/build/lib/useLocalStorage.esm.js +0 -40
  116. package/build/lib/useLocalStorage.esm.js.map +0 -1
  117. package/build/lib/useLocalStorage.js +0 -63
  118. package/build/lib/useLocalStorage.js.map +0 -1
  119. package/build/lib/useLocalStorage.mjs +0 -40
  120. package/build/lib/useLocalStorage.mjs.map +0 -1
  121. package/build/lib/useMediaQuery.d.ts +0 -2
  122. package/build/lib/useMediaQuery.esm.js +0 -36
  123. package/build/lib/useMediaQuery.esm.js.map +0 -1
  124. package/build/lib/useMediaQuery.js +0 -59
  125. package/build/lib/useMediaQuery.js.map +0 -1
  126. package/build/lib/useMediaQuery.mjs +0 -36
  127. package/build/lib/useMediaQuery.mjs.map +0 -1
  128. package/build/lib/useSubscribeToQueryCache.d.ts +0 -4
  129. package/build/lib/useSubscribeToQueryCache.d.ts.map +0 -1
  130. package/build/lib/useSubscribeToQueryCache.esm.js +0 -15
  131. package/build/lib/useSubscribeToQueryCache.esm.js.map +0 -1
  132. package/build/lib/useSubscribeToQueryCache.js +0 -19
  133. package/build/lib/useSubscribeToQueryCache.js.map +0 -1
  134. package/build/lib/useSubscribeToQueryCache.mjs +0 -15
  135. package/build/lib/useSubscribeToQueryCache.mjs.map +0 -1
  136. package/build/lib/utils.d.ts +0 -80
  137. package/build/lib/utils.d.ts.map +0 -1
  138. package/build/lib/utils.esm.js +0 -184
  139. package/build/lib/utils.esm.js.map +0 -1
  140. package/build/lib/utils.js +0 -218
  141. package/build/lib/utils.js.map +0 -1
  142. package/build/lib/utils.mjs +0 -184
  143. package/build/lib/utils.mjs.map +0 -1
  144. package/src/CachePanel/ActiveQuery.tsx +0 -388
  145. package/src/CachePanel/CachePanel.tsx +0 -439
  146. package/src/CachePanel/Header/QueryStatusCount.tsx +0 -93
  147. package/src/CachePanel/QueryRow.tsx +0 -125
  148. package/src/Explorer.tsx +0 -385
  149. package/src/Logo.tsx +0 -32
  150. package/src/__tests__/Explorer.test.tsx +0 -150
  151. package/src/noop.ts +0 -7
  152. package/src/screenreader.tsx +0 -16
  153. package/src/styledComponents.ts +0 -126
  154. package/src/theme.tsx +0 -33
  155. package/src/types.ts +0 -12
  156. package/src/useLocalStorage.ts +0 -52
  157. package/src/useMediaQuery.ts +0 -34
  158. package/src/useSubscribeToQueryCache.ts +0 -26
  159. package/src/utils.ts +0 -319
@@ -1,388 +0,0 @@
1
- import React from 'react'
2
- import type { QueryCache, QueryClient } from '@tanstack/react-query'
3
-
4
- import useSubscribeToQueryCache from '../useSubscribeToQueryCache'
5
- import { Button, Code, Select, ActiveQueryPanel } from '../styledComponents'
6
-
7
- import {
8
- getQueryStatusLabel,
9
- getQueryStatusColor,
10
- displayValue,
11
- } from '../utils'
12
- import Explorer from '../Explorer'
13
- import type { DevToolsErrorType } from '../types'
14
- import { defaultTheme as theme } from '../theme'
15
-
16
- // eslint-disable-next-line @typescript-eslint/no-empty-function
17
- function noop() {}
18
-
19
- /**
20
- * Panel for the query currently being inspected
21
- *
22
- * It displays query details (key, observers...), query actions,
23
- * the data explorer and the query explorer
24
- */
25
- const ActiveQuery = ({
26
- queryCache,
27
- activeQueryHash,
28
- queryClient,
29
- errorTypes,
30
- }: {
31
- queryCache: QueryCache
32
- activeQueryHash: string
33
- queryClient: QueryClient
34
- errorTypes: DevToolsErrorType[]
35
- }) => {
36
- const activeQuery = useSubscribeToQueryCache(queryCache, () =>
37
- queryCache.getAll().find((query) => query.queryHash === activeQueryHash),
38
- )
39
-
40
- const activeQueryState = useSubscribeToQueryCache(
41
- queryCache,
42
- () =>
43
- queryCache.getAll().find((query) => query.queryHash === activeQueryHash)
44
- ?.state,
45
- )
46
-
47
- const isStale =
48
- useSubscribeToQueryCache(queryCache, () =>
49
- queryCache
50
- .getAll()
51
- .find((query) => query.queryHash === activeQueryHash)
52
- ?.isStale(),
53
- ) ?? false
54
-
55
- const observerCount =
56
- useSubscribeToQueryCache(queryCache, () =>
57
- queryCache
58
- .getAll()
59
- .find((query) => query.queryHash === activeQueryHash)
60
- ?.getObserversCount(),
61
- ) ?? 0
62
-
63
- const handleRefetch = () => {
64
- const promise = activeQuery?.fetch()
65
- promise?.catch(noop)
66
- }
67
-
68
- const currentErrorTypeName = React.useMemo(() => {
69
- if (activeQuery && activeQueryState?.error) {
70
- const errorType = errorTypes.find(
71
- (type) =>
72
- type.initializer(activeQuery).toString() ===
73
- activeQueryState.error?.toString(),
74
- )
75
- return errorType?.name
76
- }
77
- return undefined
78
- }, [activeQuery, activeQueryState?.error, errorTypes])
79
-
80
- if (!activeQuery || !activeQueryState) {
81
- return null
82
- }
83
-
84
- const triggerError = (errorType?: DevToolsErrorType) => {
85
- const error =
86
- errorType?.initializer(activeQuery) ??
87
- new Error('Unknown error from devtools')
88
-
89
- const __previousQueryOptions = activeQuery.options
90
-
91
- activeQuery.setState({
92
- status: 'error',
93
- error,
94
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
95
- fetchMeta: {
96
- ...activeQuery.state.fetchMeta,
97
- __previousQueryOptions,
98
- } as any,
99
- })
100
- }
101
-
102
- const restoreQueryAfterLoadingOrError = () => {
103
- activeQuery.fetch(
104
- (activeQuery.state.fetchMeta as any)?.__previousQueryOptions,
105
- {
106
- // Make sure this fetch will cancel the previous one
107
- cancelRefetch: true,
108
- },
109
- )
110
- }
111
-
112
- return (
113
- <ActiveQueryPanel>
114
- <div
115
- style={{
116
- padding: '.5em',
117
- background: theme.backgroundAlt,
118
- position: 'sticky',
119
- top: 0,
120
- zIndex: 1,
121
- }}
122
- >
123
- Query Details
124
- </div>
125
- <div
126
- style={{
127
- padding: '.5em',
128
- }}
129
- >
130
- <div
131
- style={{
132
- marginBottom: '.5em',
133
- display: 'flex',
134
- alignItems: 'flex-start',
135
- justifyContent: 'space-between',
136
- }}
137
- >
138
- <Code
139
- style={{
140
- lineHeight: '1.8em',
141
- }}
142
- >
143
- <pre
144
- style={{
145
- margin: 0,
146
- padding: 0,
147
- overflow: 'auto',
148
- }}
149
- >
150
- {displayValue(activeQuery.queryKey, true)}
151
- </pre>
152
- </Code>
153
- <span
154
- style={{
155
- padding: '0.3em .6em',
156
- borderRadius: '0.4em',
157
- fontWeight: 'bold',
158
- textShadow: '0 2px 10px black',
159
- background: getQueryStatusColor({
160
- queryState: activeQueryState,
161
- isStale: isStale,
162
- observerCount: observerCount,
163
- theme,
164
- }),
165
- flexShrink: 0,
166
- }}
167
- >
168
- {getQueryStatusLabel(activeQuery)}
169
- </span>
170
- </div>
171
- <div
172
- style={{
173
- marginBottom: '.5em',
174
- display: 'flex',
175
- alignItems: 'center',
176
- justifyContent: 'space-between',
177
- }}
178
- >
179
- Observers: <Code>{observerCount}</Code>
180
- </div>
181
- <div
182
- style={{
183
- display: 'flex',
184
- alignItems: 'center',
185
- justifyContent: 'space-between',
186
- }}
187
- >
188
- Last Updated:{' '}
189
- <Code>
190
- {new Date(activeQueryState.dataUpdatedAt).toLocaleTimeString()}
191
- </Code>
192
- </div>
193
- </div>
194
- <div
195
- style={{
196
- background: theme.backgroundAlt,
197
- padding: '.5em',
198
- position: 'sticky',
199
- top: 0,
200
- zIndex: 1,
201
- }}
202
- >
203
- Actions
204
- </div>
205
- <div
206
- style={{
207
- padding: '0.5em',
208
- display: 'flex',
209
- flexWrap: 'wrap',
210
- gap: '0.5em',
211
- alignItems: 'flex-end',
212
- }}
213
- >
214
- <Button
215
- type="button"
216
- onClick={handleRefetch}
217
- disabled={activeQueryState.fetchStatus === 'fetching'}
218
- style={{
219
- background: theme.active,
220
- }}
221
- >
222
- Refetch
223
- </Button>{' '}
224
- <Button
225
- type="button"
226
- onClick={() => queryClient.invalidateQueries(activeQuery)}
227
- style={{
228
- background: theme.warning,
229
- color: theme.inputTextColor,
230
- }}
231
- >
232
- Invalidate
233
- </Button>{' '}
234
- <Button
235
- type="button"
236
- onClick={() => queryClient.resetQueries(activeQuery)}
237
- style={{
238
- background: theme.gray,
239
- }}
240
- >
241
- Reset
242
- </Button>{' '}
243
- <Button
244
- type="button"
245
- onClick={() => queryClient.removeQueries(activeQuery)}
246
- style={{
247
- background: theme.danger,
248
- }}
249
- >
250
- Remove
251
- </Button>{' '}
252
- <Button
253
- type="button"
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
- }
263
- if (activeQuery.state.data === undefined) {
264
- restoreQueryAfterLoadingOrError()
265
- } else {
266
- const __previousQueryOptions = activeQuery.options
267
- // Trigger a fetch in order to trigger suspense as well.
268
- activeQuery.fetch({
269
- ...__previousQueryOptions,
270
- queryFn: () => {
271
- return new Promise(() => {
272
- // Never resolve
273
- })
274
- },
275
- gcTime: -1,
276
- })
277
- activeQuery.setState({
278
- data: undefined,
279
- status: 'pending',
280
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
281
- fetchMeta: {
282
- ...activeQuery.state.fetchMeta,
283
- __previousQueryOptions,
284
- } as any,
285
- })
286
- }
287
- }}
288
- style={{
289
- background: theme.paused,
290
- }}
291
- >
292
- {activeQuery.state.status === 'pending' ? 'Restore' : 'Trigger'}{' '}
293
- loading
294
- </Button>{' '}
295
- {errorTypes.length === 0 || activeQuery.state.status === 'error' ? (
296
- <Button
297
- type="button"
298
- onClick={() => {
299
- if (!activeQuery.state.error) {
300
- triggerError()
301
- } else {
302
- queryClient.resetQueries(activeQuery)
303
- }
304
- }}
305
- style={{
306
- background: theme.danger,
307
- }}
308
- >
309
- {activeQuery.state.status === 'error' ? 'Restore' : 'Trigger'} error
310
- </Button>
311
- ) : (
312
- <label>
313
- Trigger error:
314
- <Select
315
- value={currentErrorTypeName ?? ''}
316
- style={{ marginInlineStart: '.5em' }}
317
- onChange={(e) => {
318
- const errorType = errorTypes.find(
319
- (t) => t.name === e.target.value,
320
- )
321
-
322
- triggerError(errorType)
323
- }}
324
- >
325
- <option key="" value="" />
326
- {errorTypes.map((errorType) => (
327
- <option key={errorType.name} value={errorType.name}>
328
- {errorType.name}
329
- </option>
330
- ))}
331
- </Select>
332
- </label>
333
- )}
334
- </div>
335
- <div
336
- style={{
337
- background: theme.backgroundAlt,
338
- padding: '.5em',
339
- position: 'sticky',
340
- top: 0,
341
- zIndex: 1,
342
- }}
343
- >
344
- Data Explorer
345
- </div>
346
- <div
347
- style={{
348
- padding: '.5em',
349
- }}
350
- >
351
- <Explorer
352
- label="Data"
353
- value={activeQueryState.data}
354
- defaultExpanded={{}}
355
- copyable
356
- />
357
- </div>
358
- <div
359
- style={{
360
- background: theme.backgroundAlt,
361
- padding: '.5em',
362
- position: 'sticky',
363
- top: 0,
364
- zIndex: 1,
365
- }}
366
- >
367
- Query Explorer
368
- </div>
369
- <div
370
- style={{
371
- padding: '.5em',
372
- }}
373
- >
374
- <Explorer
375
- label="Query"
376
- value={activeQuery}
377
- defaultExpanded={{
378
- queryKey: true,
379
- }}
380
- />
381
- </div>
382
- </ActiveQueryPanel>
383
- )
384
- }
385
-
386
- ActiveQuery.displayName = 'ActiveQuery'
387
-
388
- export default ActiveQuery