@tanstack/react-query-devtools 4.24.10 → 5.0.0-alpha.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.
- package/build/lib/Explorer.d.ts +4 -4
- package/build/lib/Explorer.esm.js +5 -15
- package/build/lib/Explorer.esm.js.map +1 -1
- package/build/lib/Explorer.js +11 -25
- package/build/lib/Explorer.js.map +1 -1
- package/build/lib/Explorer.mjs +5 -15
- package/build/lib/Explorer.mjs.map +1 -1
- package/build/lib/Logo.d.ts +0 -1
- package/build/lib/Logo.esm.js.map +1 -1
- package/build/lib/Logo.js +5 -6
- package/build/lib/Logo.js.map +1 -1
- package/build/lib/Logo.mjs.map +1 -1
- package/build/lib/__tests__/devtools.test.d.ts +0 -5
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +1 -5
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
- package/build/lib/devtools.d.ts +12 -4
- package/build/lib/devtools.esm.js +73 -108
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +95 -133
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +73 -108
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +0 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/index.prod.d.ts +2 -2
- package/build/lib/index.prod.esm.js +121 -176
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +126 -187
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +121 -176
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/lib/screenreader.d.ts +0 -1
- package/build/lib/screenreader.esm.js.map +1 -1
- package/build/lib/screenreader.js +4 -5
- package/build/lib/screenreader.js.map +1 -1
- package/build/lib/screenreader.mjs.map +1 -1
- package/build/lib/styledComponents.esm.js +17 -16
- package/build/lib/styledComponents.esm.js.map +1 -1
- package/build/lib/styledComponents.js +17 -18
- package/build/lib/styledComponents.js.map +1 -1
- package/build/lib/styledComponents.mjs +17 -16
- package/build/lib/styledComponents.mjs.map +1 -1
- package/build/lib/theme.esm.js.map +1 -1
- package/build/lib/theme.js +4 -7
- package/build/lib/theme.js.map +1 -1
- package/build/lib/theme.mjs.map +1 -1
- package/build/lib/useLocalStorage.esm.js +0 -7
- package/build/lib/useLocalStorage.esm.js.map +1 -1
- package/build/lib/useLocalStorage.js +4 -12
- package/build/lib/useLocalStorage.js.map +1 -1
- package/build/lib/useLocalStorage.mjs +0 -7
- package/build/lib/useLocalStorage.mjs.map +1 -1
- package/build/lib/useMediaQuery.esm.js +6 -6
- package/build/lib/useMediaQuery.esm.js.map +1 -1
- package/build/lib/useMediaQuery.js +10 -11
- package/build/lib/useMediaQuery.js.map +1 -1
- package/build/lib/useMediaQuery.mjs +6 -6
- package/build/lib/useMediaQuery.mjs.map +1 -1
- package/build/lib/utils.esm.js +20 -22
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +24 -32
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +20 -22
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +124 -439
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +6 -10
- package/src/Explorer.tsx +4 -4
- package/src/__tests__/Explorer.test.tsx +5 -0
- package/src/__tests__/devtools.test.tsx +121 -175
- package/src/__tests__/utils.tsx +2 -2
- package/src/devtools.tsx +110 -116
- package/src/index.ts +2 -2
- package/build/lib/useSyncExternalStore.d.ts +0 -1
- package/build/lib/useSyncExternalStore.native.d.ts +0 -1
- package/src/useSyncExternalStore.native.ts +0 -3
- package/src/useSyncExternalStore.ts +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryDevtools={})}(this,(function(e){"use strict";e.ReactQueryDevtools=function(){return null},e.ReactQueryDevtoolsPanel=function(){return null}
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryDevtools={})}(this,(function(e){"use strict";e.ReactQueryDevtools=function(){return null},e.ReactQueryDevtoolsPanel=function(){return null}}));
|
|
2
2
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["import * as devtools from './devtools'\n\nexport const ReactQueryDevtools: typeof devtools['ReactQueryDevtools'] =\n process.env.NODE_ENV !== 'development'\n ? function () {\n return null\n }\n : devtools.ReactQueryDevtools\n\nexport const ReactQueryDevtoolsPanel: typeof devtools['ReactQueryDevtoolsPanel'] =\n process.env.NODE_ENV !== 'development'\n ? (function () {\n return null\n } as any)\n : devtools.ReactQueryDevtoolsPanel\n"],"names":[],"mappings":"+QAIM,WACE,OAAO,gCAMR,WACC,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["import * as devtools from './devtools'\n\nexport const ReactQueryDevtools: (typeof devtools)['ReactQueryDevtools'] =\n process.env.NODE_ENV !== 'development'\n ? function () {\n return null\n }\n : devtools.ReactQueryDevtools\n\nexport const ReactQueryDevtoolsPanel: (typeof devtools)['ReactQueryDevtoolsPanel'] =\n process.env.NODE_ENV !== 'development'\n ? (function () {\n return null\n } as any)\n : devtools.ReactQueryDevtoolsPanel\n"],"names":[],"mappings":"+QAIM,WACE,OAAO,gCAMR,WACC,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query-devtools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.0",
|
|
4
4
|
"description": "Developer tools to interact with and visualize the TanStack/react-query cache",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,23 +40,19 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/react": "^18.0.14",
|
|
42
42
|
"@types/react-dom": "^18.0.5",
|
|
43
|
-
"@types/use-sync-external-store": "^0.0.3",
|
|
44
43
|
"react": "^18.2.0",
|
|
45
|
-
"react-17": "npm:react@^17.0.2",
|
|
46
44
|
"react-dom": "^18.2.0",
|
|
47
|
-
"react-dom-17": "npm:react-dom@^17.0.2",
|
|
48
45
|
"react-error-boundary": "^3.1.4",
|
|
49
|
-
"@tanstack/react-query": "
|
|
46
|
+
"@tanstack/react-query": "5.0.0-alpha.0"
|
|
50
47
|
},
|
|
51
48
|
"dependencies": {
|
|
52
49
|
"@tanstack/match-sorter-utils": "^8.7.0",
|
|
53
|
-
"superjson": "^1.10.0"
|
|
54
|
-
"use-sync-external-store": "^1.2.0"
|
|
50
|
+
"superjson": "^1.10.0"
|
|
55
51
|
},
|
|
56
52
|
"peerDependencies": {
|
|
57
|
-
"react": "^
|
|
58
|
-
"react-dom": "^
|
|
59
|
-
"@tanstack/react-query": "
|
|
53
|
+
"react": "^18.0.0",
|
|
54
|
+
"react-dom": "^18.0.0",
|
|
55
|
+
"@tanstack/react-query": "5.0.0-alpha.0"
|
|
60
56
|
},
|
|
61
57
|
"scripts": {
|
|
62
58
|
"clean": "rimraf ./build",
|
package/src/Explorer.tsx
CHANGED
|
@@ -183,16 +183,16 @@ const CopiedCopier = () => (
|
|
|
183
183
|
</span>
|
|
184
184
|
)
|
|
185
185
|
|
|
186
|
-
type
|
|
186
|
+
type EntryType = {
|
|
187
187
|
label: string
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
type RendererProps = {
|
|
191
|
-
handleEntry: (entry:
|
|
191
|
+
handleEntry: (entry: EntryType) => JSX.Element
|
|
192
192
|
label?: string
|
|
193
193
|
value: unknown
|
|
194
|
-
subEntries:
|
|
195
|
-
subEntryPages:
|
|
194
|
+
subEntries: EntryType[]
|
|
195
|
+
subEntryPages: EntryType[][]
|
|
196
196
|
type: string
|
|
197
197
|
expanded: boolean
|
|
198
198
|
copyable: boolean
|
|
@@ -90,6 +90,9 @@ describe('Explorer', () => {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
it('when the copy button is clicked but there is an error, show error state', async () => {
|
|
93
|
+
const consoleMock = jest.spyOn(console, 'error')
|
|
94
|
+
consoleMock.mockImplementation(() => undefined)
|
|
95
|
+
|
|
93
96
|
// Mock clipboard with error state
|
|
94
97
|
Object.defineProperty(navigator, 'clipboard', {
|
|
95
98
|
value: {
|
|
@@ -117,6 +120,8 @@ describe('Explorer', () => {
|
|
|
117
120
|
|
|
118
121
|
// Check that it has failed
|
|
119
122
|
await screen.findByLabelText('Failed copying to clipboard')
|
|
123
|
+
expect(consoleMock).toHaveBeenCalled()
|
|
124
|
+
consoleMock.mockRestore()
|
|
120
125
|
})
|
|
121
126
|
})
|
|
122
127
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { fireEvent, screen, waitFor, act } from '@testing-library/react'
|
|
3
|
-
import { ErrorBoundary } from 'react-error-boundary'
|
|
4
3
|
import '@testing-library/jest-dom'
|
|
5
|
-
import type { QueryClient } from '@tanstack/react-query'
|
|
6
4
|
import { useQuery } from '@tanstack/react-query'
|
|
7
5
|
import { defaultPanelSize, sortFns } from '../utils'
|
|
8
6
|
import {
|
|
@@ -12,13 +10,6 @@ import {
|
|
|
12
10
|
createQueryClient,
|
|
13
11
|
} from './utils'
|
|
14
12
|
|
|
15
|
-
// TODO: This should be removed with the types for react-error-boundary get updated.
|
|
16
|
-
declare module 'react-error-boundary' {
|
|
17
|
-
interface ErrorBoundaryPropsWithFallback {
|
|
18
|
-
children: any
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
13
|
Object.defineProperty(window, 'matchMedia', {
|
|
23
14
|
writable: true,
|
|
24
15
|
value: jest.fn().mockImplementation((query: string) => ({
|
|
@@ -44,9 +35,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
44
35
|
const onToggleClick = jest.fn()
|
|
45
36
|
|
|
46
37
|
function Page() {
|
|
47
|
-
const { data = 'default' } = useQuery(
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
const { data = 'default' } = useQuery({
|
|
39
|
+
queryKey: ['check'],
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
await sleep(10)
|
|
42
|
+
return 'test'
|
|
43
|
+
},
|
|
50
44
|
})
|
|
51
45
|
|
|
52
46
|
return (
|
|
@@ -118,9 +112,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
118
112
|
const { queryClient } = createQueryClient()
|
|
119
113
|
|
|
120
114
|
function Page() {
|
|
121
|
-
const { data = 'default' } = useQuery(
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
const { data = 'default' } = useQuery({
|
|
116
|
+
queryKey: ['check'],
|
|
117
|
+
queryFn: async () => {
|
|
118
|
+
await sleep(10)
|
|
119
|
+
return 'test'
|
|
120
|
+
},
|
|
124
121
|
})
|
|
125
122
|
|
|
126
123
|
return (
|
|
@@ -151,14 +148,14 @@ describe('ReactQueryDevtools', () => {
|
|
|
151
148
|
const { queryClient, queryCache } = createQueryClient()
|
|
152
149
|
|
|
153
150
|
function Page() {
|
|
154
|
-
const { data = 'default' } = useQuery(
|
|
155
|
-
['check'],
|
|
156
|
-
async () => {
|
|
151
|
+
const { data = 'default' } = useQuery({
|
|
152
|
+
queryKey: ['check'],
|
|
153
|
+
queryFn: async () => {
|
|
157
154
|
await sleep(100)
|
|
158
155
|
return 'test'
|
|
159
156
|
},
|
|
160
|
-
|
|
161
|
-
)
|
|
157
|
+
staleTime: 300,
|
|
158
|
+
})
|
|
162
159
|
|
|
163
160
|
return (
|
|
164
161
|
<div>
|
|
@@ -193,7 +190,7 @@ describe('ReactQueryDevtools', () => {
|
|
|
193
190
|
screen.getByRole('button', { name: /open react query devtools/i }),
|
|
194
191
|
)
|
|
195
192
|
|
|
196
|
-
const currentQuery = queryCache.find(['check'])
|
|
193
|
+
const currentQuery = queryCache.find({ queryKey: ['check'] })
|
|
197
194
|
|
|
198
195
|
// When the query is fetching then expect number of
|
|
199
196
|
// fetching queries to be 1
|
|
@@ -243,9 +240,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
243
240
|
const { queryClient, queryCache } = createQueryClient()
|
|
244
241
|
|
|
245
242
|
function Page() {
|
|
246
|
-
const { data = 'default' } = useQuery(
|
|
247
|
-
|
|
248
|
-
|
|
243
|
+
const { data = 'default' } = useQuery({
|
|
244
|
+
queryKey: ['check'],
|
|
245
|
+
queryFn: async () => {
|
|
246
|
+
await sleep(10)
|
|
247
|
+
return 'test'
|
|
248
|
+
},
|
|
249
249
|
})
|
|
250
250
|
|
|
251
251
|
return (
|
|
@@ -261,7 +261,7 @@ describe('ReactQueryDevtools', () => {
|
|
|
261
261
|
screen.getByRole('button', { name: /open react query devtools/i }),
|
|
262
262
|
)
|
|
263
263
|
|
|
264
|
-
const currentQuery = queryCache.find(['check'])
|
|
264
|
+
const currentQuery = queryCache.find({ queryKey: ['check'] })
|
|
265
265
|
|
|
266
266
|
await screen.findByText(getByTextContent(`1${currentQuery?.queryHash}`))
|
|
267
267
|
|
|
@@ -278,19 +278,28 @@ describe('ReactQueryDevtools', () => {
|
|
|
278
278
|
const { queryClient, queryCache } = createQueryClient()
|
|
279
279
|
|
|
280
280
|
function Page() {
|
|
281
|
-
const fooResult = useQuery(
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
const fooResult = useQuery({
|
|
282
|
+
queryKey: ['foo'],
|
|
283
|
+
queryFn: async () => {
|
|
284
|
+
await sleep(10)
|
|
285
|
+
return 'foo-result'
|
|
286
|
+
},
|
|
284
287
|
})
|
|
285
288
|
|
|
286
|
-
const barResult = useQuery(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
const barResult = useQuery({
|
|
290
|
+
queryKey: ['bar'],
|
|
291
|
+
queryFn: async () => {
|
|
292
|
+
await sleep(10)
|
|
293
|
+
return 'bar-result'
|
|
294
|
+
},
|
|
289
295
|
})
|
|
290
296
|
|
|
291
|
-
const bazResult = useQuery(
|
|
292
|
-
|
|
293
|
-
|
|
297
|
+
const bazResult = useQuery({
|
|
298
|
+
queryKey: ['baz'],
|
|
299
|
+
queryFn: async () => {
|
|
300
|
+
await sleep(10)
|
|
301
|
+
return 'baz-result'
|
|
302
|
+
},
|
|
294
303
|
})
|
|
295
304
|
|
|
296
305
|
return (
|
|
@@ -308,9 +317,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
308
317
|
screen.getByRole('button', { name: /open react query devtools/i }),
|
|
309
318
|
)
|
|
310
319
|
|
|
311
|
-
const fooQueryHash =
|
|
312
|
-
|
|
313
|
-
const
|
|
320
|
+
const fooQueryHash =
|
|
321
|
+
queryCache.find({ queryKey: ['foo'] })?.queryHash ?? 'invalid hash'
|
|
322
|
+
const barQueryHash =
|
|
323
|
+
queryCache.find({ queryKey: ['bar'] })?.queryHash ?? 'invalid hash'
|
|
324
|
+
const bazQueryHash =
|
|
325
|
+
queryCache.find({ queryKey: ['baz'] })?.queryHash ?? 'invalid hash'
|
|
314
326
|
|
|
315
327
|
await screen.findByText(fooQueryHash)
|
|
316
328
|
screen.getByText(barQueryHash)
|
|
@@ -333,16 +345,14 @@ describe('ReactQueryDevtools', () => {
|
|
|
333
345
|
|
|
334
346
|
function Page() {
|
|
335
347
|
const [enabled, setEnabled] = React.useState(false)
|
|
336
|
-
const { data } = useQuery(
|
|
337
|
-
['key'],
|
|
338
|
-
async () => {
|
|
348
|
+
const { data } = useQuery({
|
|
349
|
+
queryKey: ['key'],
|
|
350
|
+
queryFn: async () => {
|
|
339
351
|
await sleep(10)
|
|
340
352
|
return 'test'
|
|
341
353
|
},
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
},
|
|
345
|
-
)
|
|
354
|
+
enabled,
|
|
355
|
+
})
|
|
346
356
|
|
|
347
357
|
return (
|
|
348
358
|
<div>
|
|
@@ -367,7 +377,9 @@ describe('ReactQueryDevtools', () => {
|
|
|
367
377
|
const { queryClient } = createQueryClient()
|
|
368
378
|
|
|
369
379
|
function Page() {
|
|
370
|
-
const { data } = useQuery(
|
|
380
|
+
const { data } = useQuery({
|
|
381
|
+
queryKey: ['key'],
|
|
382
|
+
queryFn: () => Promise.resolve('test'),
|
|
371
383
|
enabled: false,
|
|
372
384
|
})
|
|
373
385
|
|
|
@@ -405,9 +417,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
405
417
|
let count = 0
|
|
406
418
|
|
|
407
419
|
function App() {
|
|
408
|
-
const { data, fetchStatus } = useQuery(
|
|
409
|
-
|
|
410
|
-
|
|
420
|
+
const { data, fetchStatus } = useQuery({
|
|
421
|
+
queryKey: ['key'],
|
|
422
|
+
queryFn: () => {
|
|
423
|
+
count++
|
|
424
|
+
return Promise.resolve('test')
|
|
425
|
+
},
|
|
411
426
|
})
|
|
412
427
|
|
|
413
428
|
return (
|
|
@@ -458,30 +473,33 @@ describe('ReactQueryDevtools', () => {
|
|
|
458
473
|
const { queryClient, queryCache } = createQueryClient()
|
|
459
474
|
|
|
460
475
|
function Page() {
|
|
461
|
-
const query1Result = useQuery(
|
|
462
|
-
|
|
463
|
-
|
|
476
|
+
const query1Result = useQuery({
|
|
477
|
+
queryKey: ['query-1'],
|
|
478
|
+
queryFn: async () => {
|
|
479
|
+
await sleep(20)
|
|
480
|
+
return 'query-1-result'
|
|
481
|
+
},
|
|
464
482
|
})
|
|
465
483
|
|
|
466
|
-
const query3Result = useQuery(
|
|
467
|
-
['query-3'],
|
|
468
|
-
async () => {
|
|
484
|
+
const query3Result = useQuery({
|
|
485
|
+
queryKey: ['query-3'],
|
|
486
|
+
queryFn: async () => {
|
|
469
487
|
await sleep(10)
|
|
470
488
|
return 'query-3-result'
|
|
471
489
|
},
|
|
472
|
-
|
|
473
|
-
|
|
490
|
+
staleTime: Infinity,
|
|
491
|
+
enabled: typeof query1Result.data === 'string',
|
|
492
|
+
})
|
|
474
493
|
|
|
475
|
-
const query2Result = useQuery(
|
|
476
|
-
['query-2'],
|
|
477
|
-
async () => {
|
|
494
|
+
const query2Result = useQuery({
|
|
495
|
+
queryKey: ['query-2'],
|
|
496
|
+
queryFn: async () => {
|
|
478
497
|
await sleep(10)
|
|
479
498
|
return 'query-2-result'
|
|
480
499
|
},
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
)
|
|
500
|
+
|
|
501
|
+
enabled: typeof query3Result.data === 'string',
|
|
502
|
+
})
|
|
485
503
|
|
|
486
504
|
return (
|
|
487
505
|
<div>
|
|
@@ -498,9 +516,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
498
516
|
screen.getByRole('button', { name: /open react query devtools/i }),
|
|
499
517
|
)
|
|
500
518
|
|
|
501
|
-
const query1Hash =
|
|
502
|
-
|
|
503
|
-
const
|
|
519
|
+
const query1Hash =
|
|
520
|
+
queryCache.find({ queryKey: ['query-1'] })?.queryHash ?? 'invalid hash'
|
|
521
|
+
const query2Hash =
|
|
522
|
+
queryCache.find({ queryKey: ['query-2'] })?.queryHash ?? 'invalid hash'
|
|
523
|
+
const query3Hash =
|
|
524
|
+
queryCache.find({ queryKey: ['query-3'] })?.queryHash ?? 'invalid hash'
|
|
504
525
|
|
|
505
526
|
const sortSelect = screen.getByLabelText(/sort queries/i)
|
|
506
527
|
let queries = []
|
|
@@ -563,9 +584,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
563
584
|
const { queryClient } = createQueryClient()
|
|
564
585
|
|
|
565
586
|
function Page() {
|
|
566
|
-
const { data = 'default' } = useQuery(
|
|
567
|
-
|
|
568
|
-
|
|
587
|
+
const { data = 'default' } = useQuery({
|
|
588
|
+
queryKey: ['check'],
|
|
589
|
+
queryFn: async () => {
|
|
590
|
+
await sleep(10)
|
|
591
|
+
return 'test'
|
|
592
|
+
},
|
|
569
593
|
})
|
|
570
594
|
|
|
571
595
|
return (
|
|
@@ -603,9 +627,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
603
627
|
const { queryClient } = createQueryClient()
|
|
604
628
|
|
|
605
629
|
function Page() {
|
|
606
|
-
const { data = 'default' } = useQuery(
|
|
607
|
-
|
|
608
|
-
|
|
630
|
+
const { data = 'default' } = useQuery({
|
|
631
|
+
queryKey: ['check'],
|
|
632
|
+
queryFn: async () => {
|
|
633
|
+
await sleep(10)
|
|
634
|
+
return 'test'
|
|
635
|
+
},
|
|
609
636
|
})
|
|
610
637
|
|
|
611
638
|
return (
|
|
@@ -632,9 +659,12 @@ describe('ReactQueryDevtools', () => {
|
|
|
632
659
|
const { queryClient } = createQueryClient()
|
|
633
660
|
|
|
634
661
|
function Page() {
|
|
635
|
-
const { data = 'default' } = useQuery(
|
|
636
|
-
|
|
637
|
-
|
|
662
|
+
const { data = 'default' } = useQuery({
|
|
663
|
+
queryKey: ['check'],
|
|
664
|
+
queryFn: async () => {
|
|
665
|
+
await sleep(10)
|
|
666
|
+
return 'test'
|
|
667
|
+
},
|
|
638
668
|
})
|
|
639
669
|
|
|
640
670
|
return (
|
|
@@ -670,107 +700,14 @@ describe('ReactQueryDevtools', () => {
|
|
|
670
700
|
await screen.findByRole('button', { name: /react query devtools/i })
|
|
671
701
|
})
|
|
672
702
|
|
|
673
|
-
describe('with custom context', () => {
|
|
674
|
-
it('should render without error when the custom context aligns', async () => {
|
|
675
|
-
const context = React.createContext<QueryClient | undefined>(undefined)
|
|
676
|
-
const { queryClient } = createQueryClient()
|
|
677
|
-
|
|
678
|
-
function Page() {
|
|
679
|
-
const { data = 'default' } = useQuery(['check'], async () => 'test', {
|
|
680
|
-
context,
|
|
681
|
-
})
|
|
682
|
-
|
|
683
|
-
return (
|
|
684
|
-
<div>
|
|
685
|
-
<h1>{data}</h1>
|
|
686
|
-
</div>
|
|
687
|
-
)
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
renderWithClient(queryClient, <Page />, {
|
|
691
|
-
initialIsOpen: false,
|
|
692
|
-
context,
|
|
693
|
-
})
|
|
694
|
-
|
|
695
|
-
await screen.findByRole('button', { name: /open react query devtools/i })
|
|
696
|
-
})
|
|
697
|
-
|
|
698
|
-
it('should render with error when the custom context is not passed to useQuery', async () => {
|
|
699
|
-
const consoleErrorMock = jest.spyOn(console, 'error')
|
|
700
|
-
consoleErrorMock.mockImplementation(() => undefined)
|
|
701
|
-
|
|
702
|
-
const context = React.createContext<QueryClient | undefined>(undefined)
|
|
703
|
-
const { queryClient } = createQueryClient()
|
|
704
|
-
|
|
705
|
-
function Page() {
|
|
706
|
-
const { data = 'default' } = useQuery(['check'], async () => 'test', {
|
|
707
|
-
useErrorBoundary: true,
|
|
708
|
-
})
|
|
709
|
-
|
|
710
|
-
return (
|
|
711
|
-
<div>
|
|
712
|
-
<h1>{data}</h1>
|
|
713
|
-
</div>
|
|
714
|
-
)
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
const rendered = renderWithClient(
|
|
718
|
-
queryClient,
|
|
719
|
-
<ErrorBoundary fallbackRender={() => <div>error boundary</div>}>
|
|
720
|
-
<Page />
|
|
721
|
-
</ErrorBoundary>,
|
|
722
|
-
{
|
|
723
|
-
initialIsOpen: false,
|
|
724
|
-
context,
|
|
725
|
-
},
|
|
726
|
-
)
|
|
727
|
-
|
|
728
|
-
await waitFor(() => rendered.getByText('error boundary'))
|
|
729
|
-
|
|
730
|
-
consoleErrorMock.mockRestore()
|
|
731
|
-
})
|
|
732
|
-
|
|
733
|
-
it('should render with error when the custom context is not passed to ReactQueryDevtools', async () => {
|
|
734
|
-
const consoleErrorMock = jest.spyOn(console, 'error')
|
|
735
|
-
consoleErrorMock.mockImplementation(() => undefined)
|
|
736
|
-
|
|
737
|
-
const context = React.createContext<QueryClient | undefined>(undefined)
|
|
738
|
-
const { queryClient } = createQueryClient()
|
|
739
|
-
|
|
740
|
-
function Page() {
|
|
741
|
-
const { data = 'default' } = useQuery(['check'], async () => 'test', {
|
|
742
|
-
useErrorBoundary: true,
|
|
743
|
-
context,
|
|
744
|
-
})
|
|
745
|
-
|
|
746
|
-
return (
|
|
747
|
-
<div>
|
|
748
|
-
<h1>{data}</h1>
|
|
749
|
-
</div>
|
|
750
|
-
)
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
const rendered = renderWithClient(
|
|
754
|
-
queryClient,
|
|
755
|
-
<ErrorBoundary fallbackRender={() => <div>error boundary</div>}>
|
|
756
|
-
<Page />
|
|
757
|
-
</ErrorBoundary>,
|
|
758
|
-
{
|
|
759
|
-
initialIsOpen: false,
|
|
760
|
-
},
|
|
761
|
-
)
|
|
762
|
-
|
|
763
|
-
await waitFor(() => rendered.getByText('error boundary'))
|
|
764
|
-
|
|
765
|
-
consoleErrorMock.mockRestore()
|
|
766
|
-
})
|
|
767
|
-
})
|
|
768
|
-
|
|
769
703
|
it('should render a menu to select panel position', async () => {
|
|
770
704
|
const { queryClient } = createQueryClient()
|
|
771
705
|
|
|
772
706
|
function Page() {
|
|
773
|
-
const { data = 'default' } = useQuery(
|
|
707
|
+
const { data = 'default' } = useQuery({
|
|
708
|
+
queryKey: ['check'],
|
|
709
|
+
queryFn: async () => 'test',
|
|
710
|
+
})
|
|
774
711
|
|
|
775
712
|
return (
|
|
776
713
|
<div>
|
|
@@ -794,7 +731,10 @@ describe('ReactQueryDevtools', () => {
|
|
|
794
731
|
const { queryClient } = createQueryClient()
|
|
795
732
|
|
|
796
733
|
function Page() {
|
|
797
|
-
const { data = 'default' } = useQuery(
|
|
734
|
+
const { data = 'default' } = useQuery({
|
|
735
|
+
queryKey: ['check'],
|
|
736
|
+
queryFn: async () => 'test',
|
|
737
|
+
})
|
|
798
738
|
|
|
799
739
|
return (
|
|
800
740
|
<div>
|
|
@@ -827,7 +767,10 @@ describe('ReactQueryDevtools', () => {
|
|
|
827
767
|
const { queryClient } = createQueryClient()
|
|
828
768
|
|
|
829
769
|
function Page() {
|
|
830
|
-
const { data = 'default' } = useQuery(
|
|
770
|
+
const { data = 'default' } = useQuery({
|
|
771
|
+
queryKey: ['check'],
|
|
772
|
+
queryFn: async () => 'test',
|
|
773
|
+
})
|
|
831
774
|
|
|
832
775
|
return (
|
|
833
776
|
<div>
|
|
@@ -869,7 +812,10 @@ describe('ReactQueryDevtools', () => {
|
|
|
869
812
|
const { queryClient } = createQueryClient()
|
|
870
813
|
|
|
871
814
|
function Page() {
|
|
872
|
-
const { data = 'default' } = useQuery(
|
|
815
|
+
const { data = 'default' } = useQuery({
|
|
816
|
+
queryKey: ['check'],
|
|
817
|
+
queryFn: async () => 'test',
|
|
818
|
+
})
|
|
873
819
|
|
|
874
820
|
return (
|
|
875
821
|
<div>
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -15,7 +15,7 @@ export function renderWithClient(
|
|
|
15
15
|
renderOptions?: RenderOptions,
|
|
16
16
|
): ReturnType<typeof render> {
|
|
17
17
|
const { rerender, ...result } = render(
|
|
18
|
-
<QueryClientProvider client={client}
|
|
18
|
+
<QueryClientProvider client={client}>
|
|
19
19
|
<ReactQueryDevtools {...devtoolsOptions} />
|
|
20
20
|
{ui}
|
|
21
21
|
</QueryClientProvider>,
|
|
@@ -25,7 +25,7 @@ export function renderWithClient(
|
|
|
25
25
|
...result,
|
|
26
26
|
rerender: (rerenderUi: React.ReactElement) =>
|
|
27
27
|
rerender(
|
|
28
|
-
<QueryClientProvider client={client}
|
|
28
|
+
<QueryClientProvider client={client}>
|
|
29
29
|
<ReactQueryDevtools {...devtoolsOptions} />
|
|
30
30
|
{rerenderUi}
|
|
31
31
|
</QueryClientProvider>,
|