@tanstack/react-query-devtools 4.24.9 → 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.
Files changed (86) hide show
  1. package/build/lib/Explorer.d.ts +4 -4
  2. package/build/lib/Explorer.esm.js +5 -15
  3. package/build/lib/Explorer.esm.js.map +1 -1
  4. package/build/lib/Explorer.js +11 -25
  5. package/build/lib/Explorer.js.map +1 -1
  6. package/build/lib/Explorer.mjs +5 -15
  7. package/build/lib/Explorer.mjs.map +1 -1
  8. package/build/lib/Logo.d.ts +0 -1
  9. package/build/lib/Logo.esm.js.map +1 -1
  10. package/build/lib/Logo.js +5 -6
  11. package/build/lib/Logo.js.map +1 -1
  12. package/build/lib/Logo.mjs.map +1 -1
  13. package/build/lib/__tests__/devtools.test.d.ts +0 -5
  14. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +0 -2
  15. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -1
  16. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +1 -5
  17. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  18. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs +0 -2
  19. package/build/lib/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
  20. package/build/lib/devtools.d.ts +12 -4
  21. package/build/lib/devtools.esm.js +73 -108
  22. package/build/lib/devtools.esm.js.map +1 -1
  23. package/build/lib/devtools.js +95 -133
  24. package/build/lib/devtools.js.map +1 -1
  25. package/build/lib/devtools.mjs +73 -108
  26. package/build/lib/devtools.mjs.map +1 -1
  27. package/build/lib/index.d.ts +2 -2
  28. package/build/lib/index.esm.js.map +1 -1
  29. package/build/lib/index.js +0 -2
  30. package/build/lib/index.js.map +1 -1
  31. package/build/lib/index.mjs.map +1 -1
  32. package/build/lib/index.prod.d.ts +2 -2
  33. package/build/lib/index.prod.esm.js +121 -176
  34. package/build/lib/index.prod.esm.js.map +1 -1
  35. package/build/lib/index.prod.js +126 -187
  36. package/build/lib/index.prod.js.map +1 -1
  37. package/build/lib/index.prod.mjs +121 -176
  38. package/build/lib/index.prod.mjs.map +1 -1
  39. package/build/lib/screenreader.d.ts +0 -1
  40. package/build/lib/screenreader.esm.js.map +1 -1
  41. package/build/lib/screenreader.js +4 -5
  42. package/build/lib/screenreader.js.map +1 -1
  43. package/build/lib/screenreader.mjs.map +1 -1
  44. package/build/lib/styledComponents.esm.js +17 -16
  45. package/build/lib/styledComponents.esm.js.map +1 -1
  46. package/build/lib/styledComponents.js +17 -18
  47. package/build/lib/styledComponents.js.map +1 -1
  48. package/build/lib/styledComponents.mjs +17 -16
  49. package/build/lib/styledComponents.mjs.map +1 -1
  50. package/build/lib/theme.esm.js.map +1 -1
  51. package/build/lib/theme.js +4 -7
  52. package/build/lib/theme.js.map +1 -1
  53. package/build/lib/theme.mjs.map +1 -1
  54. package/build/lib/useLocalStorage.esm.js +0 -7
  55. package/build/lib/useLocalStorage.esm.js.map +1 -1
  56. package/build/lib/useLocalStorage.js +4 -12
  57. package/build/lib/useLocalStorage.js.map +1 -1
  58. package/build/lib/useLocalStorage.mjs +0 -7
  59. package/build/lib/useLocalStorage.mjs.map +1 -1
  60. package/build/lib/useMediaQuery.esm.js +6 -6
  61. package/build/lib/useMediaQuery.esm.js.map +1 -1
  62. package/build/lib/useMediaQuery.js +10 -11
  63. package/build/lib/useMediaQuery.js.map +1 -1
  64. package/build/lib/useMediaQuery.mjs +6 -6
  65. package/build/lib/useMediaQuery.mjs.map +1 -1
  66. package/build/lib/utils.esm.js +20 -22
  67. package/build/lib/utils.esm.js.map +1 -1
  68. package/build/lib/utils.js +24 -32
  69. package/build/lib/utils.js.map +1 -1
  70. package/build/lib/utils.mjs +20 -22
  71. package/build/lib/utils.mjs.map +1 -1
  72. package/build/umd/index.development.js +124 -439
  73. package/build/umd/index.development.js.map +1 -1
  74. package/build/umd/index.production.js +1 -1
  75. package/build/umd/index.production.js.map +1 -1
  76. package/package.json +6 -10
  77. package/src/Explorer.tsx +4 -4
  78. package/src/__tests__/Explorer.test.tsx +5 -0
  79. package/src/__tests__/devtools.test.tsx +121 -175
  80. package/src/__tests__/utils.tsx +2 -2
  81. package/src/devtools.tsx +110 -116
  82. package/src/index.ts +2 -2
  83. package/build/lib/useSyncExternalStore.d.ts +0 -1
  84. package/build/lib/useSyncExternalStore.native.d.ts +0 -1
  85. package/src/useSyncExternalStore.native.ts +0 -3
  86. package/src/useSyncExternalStore.ts +0 -2
package/src/devtools.tsx CHANGED
@@ -1,11 +1,9 @@
1
1
  'use client'
2
2
  import * as React from 'react'
3
- import { useSyncExternalStore } from './useSyncExternalStore'
4
3
  import type {
5
4
  QueryCache,
6
5
  QueryClient,
7
6
  QueryKey as QueryKeyType,
8
- ContextOptions,
9
7
  } from '@tanstack/react-query'
10
8
  import {
11
9
  useQueryClient,
@@ -42,7 +40,7 @@ import { getQueryStatusLabel, getQueryStatusColor } from './utils'
42
40
  import Explorer from './Explorer'
43
41
  import Logo from './Logo'
44
42
 
45
- export interface DevtoolsOptions extends ContextOptions {
43
+ export interface DevtoolsOptions {
46
44
  /**
47
45
  * Set this true if you want the dev tools to default to being open
48
46
  */
@@ -79,9 +77,13 @@ export interface DevtoolsOptions extends ContextOptions {
79
77
  * nonce for style element for CSP
80
78
  */
81
79
  styleNonce?: string
80
+ /**
81
+ * Custom instance of QueryClient
82
+ */
83
+ queryClient?: QueryClient
82
84
  }
83
85
 
84
- interface DevtoolsPanelOptions extends ContextOptions {
86
+ interface DevtoolsPanelOptions {
85
87
  /**
86
88
  * The standard React style object used to style a component with inline styles
87
89
  */
@@ -123,6 +125,10 @@ interface DevtoolsPanelOptions extends ContextOptions {
123
125
  * Use this to add props to the close button. For example, you can add className, style (merge and override default style), onClick (extend default handler), etc.
124
126
  */
125
127
  closeButtonProps?: React.ComponentPropsWithoutRef<'button'>
128
+ /**
129
+ * Custom instance of QueryClient
130
+ */
131
+ queryClient?: QueryClient
126
132
  }
127
133
 
128
134
  export function ReactQueryDevtools({
@@ -132,7 +138,7 @@ export function ReactQueryDevtools({
132
138
  toggleButtonProps = {},
133
139
  position = 'bottom-left',
134
140
  containerElement: Container = 'aside',
135
- context,
141
+ queryClient,
136
142
  styleNonce,
137
143
  panelPosition: initialPanelPosition = 'bottom',
138
144
  }: DevtoolsOptions): React.ReactElement | null {
@@ -332,7 +338,7 @@ export function ReactQueryDevtools({
332
338
  <ThemeProvider theme={theme}>
333
339
  <ReactQueryDevtoolsPanel
334
340
  ref={panelRef as any}
335
- context={context}
341
+ queryClient={queryClient}
336
342
  styleNonce={styleNonce}
337
343
  position={panelPosition}
338
344
  onPositionChange={setPanelPosition}
@@ -403,7 +409,7 @@ const useSubscribeToQueryCache = <T,>(
403
409
  getSnapshot: () => T,
404
410
  skip: boolean = false,
405
411
  ): T => {
406
- return useSyncExternalStore(
412
+ return React.useSyncExternalStore(
407
413
  React.useCallback(
408
414
  (onStoreChange) => {
409
415
  if (!skip)
@@ -427,7 +433,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
427
433
  isOpen = true,
428
434
  styleNonce,
429
435
  setIsOpen,
430
- context,
436
+ queryClient,
431
437
  onDragStart,
432
438
  onPositionChange,
433
439
  showCloseButton,
@@ -438,8 +444,8 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
438
444
 
439
445
  const { onClick: onCloseClick, ...otherCloseButtonProps } = closeButtonProps
440
446
 
441
- const queryClient = useQueryClient({ context })
442
- const queryCache = queryClient.getQueryCache()
447
+ const client = useQueryClient(queryClient)
448
+ const queryCache = client.getQueryCache()
443
449
 
444
450
  const [sort, setSort] = useLocalStorage(
445
451
  'reactQueryDevtoolsSortFn',
@@ -621,106 +627,94 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
621
627
  width: '100%',
622
628
  }}
623
629
  />
624
- {!filter ? (
625
- <>
626
- <Select
627
- aria-label="Sort queries"
628
- value={sort}
629
- onChange={(e) => setSort(e.target.value)}
630
- style={{
631
- flex: '1',
632
- minWidth: 75,
633
- marginRight: '.5em',
634
- }}
635
- >
636
- {Object.keys(sortFns).map((key) => (
637
- <option key={key} value={key}>
638
- Sort by {key}
639
- </option>
640
- ))}
641
- </Select>
642
- <Button
643
- type="button"
644
- onClick={() => setBaseSort((old) => old * -1)}
645
- style={{
646
- padding: '.3em .4em',
647
- marginRight: '.5em',
648
- }}
649
- >
650
- {baseSort === 1 ? '⬆ Asc' : '⬇ Desc'}
651
- </Button>
652
- <Button
653
- type="button"
654
- onClick={() => {
655
- if (isMockOffline) {
656
- onlineManager.setOnline(undefined)
657
- setMockOffline(false)
658
- window.dispatchEvent(new Event('online'))
659
- } else {
660
- onlineManager.setOnline(false)
661
- setMockOffline(true)
662
- }
663
- }}
664
- aria-label={
665
- isMockOffline
666
- ? 'Restore offline mock'
667
- : 'Mock offline behavior'
668
- }
669
- title={
670
- isMockOffline
671
- ? 'Restore offline mock'
672
- : 'Mock offline behavior'
673
- }
674
- style={{
675
- padding: '0',
676
- height: '2em',
677
- }}
678
- >
679
- <svg
680
- xmlns="http://www.w3.org/2000/svg"
681
- width="2em"
682
- height="2em"
683
- viewBox="0 0 24 24"
684
- stroke={isMockOffline ? theme.danger : 'currentColor'}
685
- fill="none"
686
- >
687
- {isMockOffline ? (
688
- <>
689
- <path
690
- stroke="none"
691
- d="M0 0h24v24H0z"
692
- fill="none"
693
- />
694
- <line x1="12" y1="18" x2="12.01" y2="18" />
695
- <path d="M9.172 15.172a4 4 0 0 1 5.656 0" />
696
- <path d="M6.343 12.343a7.963 7.963 0 0 1 3.864 -2.14m4.163 .155a7.965 7.965 0 0 1 3.287 2" />
697
- <path d="M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374" />
698
- <line x1="3" y1="3" x2="21" y2="21" />
699
- </>
700
- ) : (
701
- <>
702
- <path
703
- stroke="none"
704
- d="M0 0h24v24H0z"
705
- fill="none"
706
- />
707
- <line x1="12" y1="18" x2="12.01" y2="18" />
708
- <path d="M9.172 15.172a4 4 0 0 1 5.656 0" />
709
- <path d="M6.343 12.343a8 8 0 0 1 11.314 0" />
710
- <path d="M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0" />
711
- </>
712
- )}
713
- </svg>
714
- <ScreenReader
715
- text={
716
- isMockOffline
717
- ? 'Restore offline mock'
718
- : 'Mock offline behavior'
719
- }
720
- />
721
- </Button>
722
- </>
723
- ) : null}
630
+ <Select
631
+ aria-label="Sort queries"
632
+ value={sort}
633
+ onChange={(e) => setSort(e.target.value)}
634
+ style={{
635
+ flex: '1',
636
+ minWidth: 75,
637
+ marginRight: '.5em',
638
+ }}
639
+ >
640
+ {Object.keys(sortFns).map((key) => (
641
+ <option key={key} value={key}>
642
+ Sort by {key}
643
+ </option>
644
+ ))}
645
+ </Select>
646
+ <Button
647
+ type="button"
648
+ onClick={() => setBaseSort((old) => old * -1)}
649
+ style={{
650
+ padding: '.3em .4em',
651
+ marginRight: '.5em',
652
+ }}
653
+ >
654
+ {baseSort === 1 ? '⬆ Asc' : '⬇ Desc'}
655
+ </Button>
656
+ <Button
657
+ type="button"
658
+ onClick={() => {
659
+ if (isMockOffline) {
660
+ onlineManager.setOnline(undefined)
661
+ setMockOffline(false)
662
+ window.dispatchEvent(new Event('online'))
663
+ } else {
664
+ onlineManager.setOnline(false)
665
+ setMockOffline(true)
666
+ }
667
+ }}
668
+ aria-label={
669
+ isMockOffline
670
+ ? 'Restore offline mock'
671
+ : 'Mock offline behavior'
672
+ }
673
+ title={
674
+ isMockOffline
675
+ ? 'Restore offline mock'
676
+ : 'Mock offline behavior'
677
+ }
678
+ style={{
679
+ padding: '0',
680
+ height: '2em',
681
+ }}
682
+ >
683
+ <svg
684
+ xmlns="http://www.w3.org/2000/svg"
685
+ width="2em"
686
+ height="2em"
687
+ viewBox="0 0 24 24"
688
+ stroke={isMockOffline ? theme.danger : 'currentColor'}
689
+ fill="none"
690
+ >
691
+ {isMockOffline ? (
692
+ <>
693
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
694
+ <line x1="12" y1="18" x2="12.01" y2="18" />
695
+ <path d="M9.172 15.172a4 4 0 0 1 5.656 0" />
696
+ <path d="M6.343 12.343a7.963 7.963 0 0 1 3.864 -2.14m4.163 .155a7.965 7.965 0 0 1 3.287 2" />
697
+ <path d="M3.515 9.515a12 12 0 0 1 3.544 -2.455m3.101 -.92a12 12 0 0 1 10.325 3.374" />
698
+ <line x1="3" y1="3" x2="21" y2="21" />
699
+ </>
700
+ ) : (
701
+ <>
702
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
703
+ <line x1="12" y1="18" x2="12.01" y2="18" />
704
+ <path d="M9.172 15.172a4 4 0 0 1 5.656 0" />
705
+ <path d="M6.343 12.343a8 8 0 0 1 11.314 0" />
706
+ <path d="M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0" />
707
+ </>
708
+ )}
709
+ </svg>
710
+ <ScreenReader
711
+ text={
712
+ isMockOffline
713
+ ? 'Restore offline mock'
714
+ : 'Mock offline behavior'
715
+ }
716
+ />
717
+ </Button>
724
718
  </div>
725
719
  </div>
726
720
  </div>
@@ -749,7 +743,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef<
749
743
  <ActiveQuery
750
744
  activeQueryHash={activeQueryHash}
751
745
  queryCache={queryCache}
752
- queryClient={queryClient}
746
+ queryClient={client}
753
747
  />
754
748
  ) : null}
755
749
 
@@ -1110,27 +1104,27 @@ const QueryRow = React.memo(
1110
1104
  const queryHash =
1111
1105
  useSubscribeToQueryCache(
1112
1106
  queryCache,
1113
- () => queryCache.find(queryKey)?.queryHash,
1107
+ () => queryCache.find({ queryKey })?.queryHash,
1114
1108
  ) ?? ''
1115
1109
 
1116
1110
  const queryState = useSubscribeToQueryCache(
1117
1111
  queryCache,
1118
- () => queryCache.find(queryKey)?.state,
1112
+ () => queryCache.find({ queryKey })?.state,
1119
1113
  )
1120
1114
 
1121
1115
  const isStale =
1122
1116
  useSubscribeToQueryCache(queryCache, () =>
1123
- queryCache.find(queryKey)?.isStale(),
1117
+ queryCache.find({ queryKey })?.isStale(),
1124
1118
  ) ?? false
1125
1119
 
1126
1120
  const isDisabled =
1127
1121
  useSubscribeToQueryCache(queryCache, () =>
1128
- queryCache.find(queryKey)?.isDisabled(),
1122
+ queryCache.find({ queryKey })?.isDisabled(),
1129
1123
  ) ?? false
1130
1124
 
1131
1125
  const observerCount =
1132
1126
  useSubscribeToQueryCache(queryCache, () =>
1133
- queryCache.find(queryKey)?.getObserversCount(),
1127
+ queryCache.find({ queryKey })?.getObserversCount(),
1134
1128
  ) ?? 0
1135
1129
 
1136
1130
  if (!queryState) {
package/src/index.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as devtools from './devtools'
2
2
 
3
- export const ReactQueryDevtools: typeof devtools['ReactQueryDevtools'] =
3
+ export const ReactQueryDevtools: (typeof devtools)['ReactQueryDevtools'] =
4
4
  process.env.NODE_ENV !== 'development'
5
5
  ? function () {
6
6
  return null
7
7
  }
8
8
  : devtools.ReactQueryDevtools
9
9
 
10
- export const ReactQueryDevtoolsPanel: typeof devtools['ReactQueryDevtoolsPanel'] =
10
+ export const ReactQueryDevtoolsPanel: (typeof devtools)['ReactQueryDevtoolsPanel'] =
11
11
  process.env.NODE_ENV !== 'development'
12
12
  ? (function () {
13
13
  return null
@@ -1 +0,0 @@
1
- export { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
@@ -1 +0,0 @@
1
- export { useSyncExternalStore } from 'use-sync-external-store/shim/index.native.js';
@@ -1,3 +0,0 @@
1
- // Temporary workaround due to an issue with react-native uSES - https://github.com/TanStack/query/pull/3601
2
- // @ts-ignore
3
- export { useSyncExternalStore } from 'use-sync-external-store/shim/index.native.js'
@@ -1,2 +0,0 @@
1
- // Temporary workaround due to an issue with react-native uSES - https://github.com/TanStack/query/pull/3601
2
- export { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'