Open History to see the last commit
1import { createEffect, createMemo, onCleanup, onMount } from 'solid-js'
2import { onlineManager, useQueryClient } from '@tanstack/solid-query'
3import { TanstackQueryDevtools } from '@tanstack/query-devtools'
4import type {
5 DevtoolsButtonPosition,
6 DevtoolsErrorType,
7 DevtoolsPosition,
8 Theme,
9} from '@tanstack/query-devtools'
10import type { QueryClient } from '@tanstack/solid-query'
11β
12interface DevtoolsOptions {
13 /**
14 * Set this true if you want the dev tools to default to being open
15 */
16 initialIsOpen?: boolean
17 /**
18 * The position of the TanStack logo to open and close the devtools panel.
19 * 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'relative'
20 * @defaultValue bottom-right
21 */
22 buttonPosition?: DevtoolsButtonPosition
23 /**
24 * The position of the Solid Query devtools panel.
25 * 'top' | 'bottom' | 'left' | 'right'
26 * @defaultValue bottom
27 */
28 position?: DevtoolsPosition
29 /**
30 * Custom instance of QueryClient
31 */
32 client?: QueryClient
33 /**
34 * Use this so you can define custom errors that can be shown in the devtools.
35 */
36 errorTypes?: Array<DevtoolsErrorType>
37 /**
38 * 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.
39 */
40 styleNonce?: string
41 /**
42 * Use this to pass a shadow DOM target to the devtools so that the styles will be applied
43 * within the shadow DOM instead of within the head tag in the light DOM.
44 */
45 shadowDOMTarget?: ShadowRoot
46 /**
47 * Set this to true to hide disabled queries from the devtools panel.
48 */
49 hideDisabledQueries?: boolean
50 /**
51 * Set this to 'light', 'dark', or 'system' to change the theme of the devtools panel.
52 * @defaultValue system
53 */
54 theme?: Theme
55}
56β
57/**
58 * Renders the TanStack Query devtools, with a toggle button that opens them, for the given or
59 * nearest `QueryClient`.
60 * @param props - The devtools options.
61 * @returns The element the devtools are mounted in.
62 */
63export default function SolidQueryDevtools(props: DevtoolsOptions) {
64 const queryClient = useQueryClient(props.client)
65 const client = createMemo(() => queryClient)
66 let ref!: HTMLDivElement
67 const devtools = new TanstackQueryDevtools({
68 client: client(),
69 queryFlavor: 'Solid Query',
70 version: '5',
71 onlineManager,
72 buttonPosition: props.buttonPosition,
73 position: props.position,
74 initialIsOpen: props.initialIsOpen,
75 errorTypes: props.errorTypes,
76 styleNonce: props.styleNonce,
77 shadowDOMTarget: props.shadowDOMTarget,
78 hideDisabledQueries: props.hideDisabledQueries,
79 theme: props.theme,
80 })
81β
82 createEffect(() => {
83 devtools.setClient(client())
84 })
85β
86 createEffect(() => {
87 const buttonPos = props.buttonPosition
88 if (buttonPos) {
89 devtools.setButtonPosition(buttonPos)
90 }
91 })
92β
93 createEffect(() => {
94 const pos = props.position
95 if (pos) {
96 devtools.setPosition(pos)
97 }
98 })
99β
100 createEffect(() => {
101 devtools.setInitialIsOpen(props.initialIsOpen || false)
102 })
103β
104 createEffect(() => {
105 devtools.setErrorTypes(props.errorTypes || [])
106 })
107β
108 createEffect(() => {
109 devtools.setTheme(props.theme || 'system')
110 })
111β
112 onMount(() => {
113 devtools.mount(ref)
114 onCleanup(() => devtools.unmount())
115 })
116β
117 return <div class="tsqd-parent-container" ref={ref} />
118}