Open History to see the last commit
1import { createEffect, createMemo, onCleanup, onMount } from 'solid-js'
2import { onlineManager, useQueryClient } from '@tanstack/solid-query'
3import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
4import type { DevtoolsErrorType, Theme } from '@tanstack/query-devtools'
5import type { QueryClient } from '@tanstack/solid-query'
6import type { JSX } from 'solid-js'
7β
8export interface DevtoolsPanelOptions {
9 /**
10 * Custom instance of QueryClient
11 */
12 client?: QueryClient
13 /**
14 * Use this so you can define custom errors that can be shown in the devtools.
15 */
16 errorTypes?: Array<DevtoolsErrorType>
17 /**
18 * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
19 */
20 styleNonce?: string
21 /**
22 * Use this so you can attach the devtool's styles to specific element in the DOM.
23 */
24 shadowDOMTarget?: ShadowRoot
25β
26 /**
27 * Custom styles for the devtools panel
28 * @default { height: '500px' }
29 * @example { height: '100%' }
30 * @example { height: '100%', width: '100%' }
31 */
32 style?: JSX.CSSProperties
33β
34 /**
35 * Callback function that is called when the devtools panel is closed
36 */
37 onClose?: () => void
38 /**
39 * Set this to true to hide disabled queries from the devtools panel.
40 */
41 hideDisabledQueries?: boolean
42 /**
43 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
44 *
45 * @defaultValue system
46 */
47 theme?: Theme
48}
49β
50export default function SolidQueryDevtoolsPanel(props: DevtoolsPanelOptions) {
51 const queryClient = useQueryClient(props.client)
52 const client = createMemo(() => queryClient)
53 let ref!: HTMLDivElement
54 const { errorTypes, styleNonce, shadowDOMTarget, hideDisabledQueries } = props
55 const devtools = new TanstackQueryDevtoolsPanel({
56 client: client(),
57 queryFlavor: 'Solid Query',
58 version: '5',
59 onlineManager,
60 buttonPosition: 'bottom-left',
61 position: 'bottom',
62 initialIsOpen: true,
63 errorTypes,
64 styleNonce,
65 shadowDOMTarget,
66 onClose: props.onClose,
67 hideDisabledQueries,
68 theme: props.theme,
69 })
70 createEffect(() => {
71 devtools.setClient(client())
72 })
73 createEffect(() => {
74 devtools.setOnClose(props.onClose ?? (() => {}))
75 })
76β
77 createEffect(() => {
78 devtools.setErrorTypes(props.errorTypes || [])
79 })
80β
81 createEffect(() => {
82 devtools.setTheme(props.theme || 'system')
83 })
84β
85 onMount(() => {
86 devtools.mount(ref)
87 onCleanup(() => devtools.unmount())
88 })
89β
90 return (
91 <div
92 style={{ height: '500px', ...props.style }}
93 class="tsqd-parent-container"
94 ref={ref}
95 />
96 )
97}