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?: () => unknown
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 * Defaults to 'system'.
45 */
46 theme?: Theme
47}
48β
49export default function SolidQueryDevtoolsPanel(props: DevtoolsPanelOptions) {
50 const queryClient = useQueryClient(props.client)
51 const client = createMemo(() => queryClient)
52 let ref!: HTMLDivElement
53 const { errorTypes, styleNonce, shadowDOMTarget, hideDisabledQueries } = props
54 const devtools = new TanstackQueryDevtoolsPanel({
55 client: client(),
56 queryFlavor: 'Solid Query',
57 version: '5',
58 onlineManager,
59 buttonPosition: 'bottom-left',
60 position: 'bottom',
61 initialIsOpen: true,
62 errorTypes,
63 styleNonce,
64 shadowDOMTarget,
65 onClose: props.onClose,
66 hideDisabledQueries,
67 theme: props.theme,
68 })
69 createEffect(() => {
70 devtools.setClient(client())
71 })
72 createEffect(() => {
73 devtools.setOnClose(props.onClose ?? (() => {}))
74 })
75β
76 createEffect(() => {
77 devtools.setErrorTypes(props.errorTypes || [])
78 })
79β
80 createEffect(() => {
81 devtools.setTheme(props.theme || 'system')
82 })
83β
84 onMount(() => {
85 devtools.mount(ref)
86 onCleanup(() => devtools.unmount())
87 })
88β
89 return (
90 <div
91 style={{ height: '500px', ...props.style }}
92 class="tsqd-parent-container"
93 ref={ref}
94 />
95 )
96}