Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

devtools.md

215 lines9.7 KB

1---
2id: devtools
3title: Devtools
4---
5​
6Wave your hands in the air and shout hooray because Solid Query comes with dedicated devtools! πŸ₯³
7​
8When you begin your Solid Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of Solid Query and will likely save you hours of debugging if you find yourself in a pinch!
9​
10> For Chrome, Firefox, and Edge users: Third-party browser extensions are available for debugging TanStack Query directly in browser DevTools. These provide the same functionality as the framework-specific devtools packages:
12> - <img alt="Chrome logo" src="https://www.google.com/chrome/static/images/chrome-logo.svg" width="16" height="16" class="inline mr-1 not-prose" /> <a href="https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai">Devtools for Chrome</a>
13> - <img alt="Firefox logo" src="https://upload.wikimedia.org/wikipedia/commons/a/a0/Firefox_logo%2C_2019.svg" width="16" height="16" class="inline mr-1 not-prose" /> <a href="https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/">Devtools for Firefox</a>
14> - <img alt="Edge logo" src="https://upload.wikimedia.org/wikipedia/commons/9/98/Microsoft_Edge_logo_%282019%29.svg" width="16" height="16" class="inline mr-1 not-prose" /> <a href="https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj">Devtools for Edge</a>
15​
16## Install and Import the Devtools
17​
18The devtools are a separate package that you need to install:
19​
20```sh
21npm i @tanstack/solid-query-devtools
22```
23​
24or
25​
26```sh
27pnpm add @tanstack/solid-query-devtools
28```
29​
30or
31​
32```sh
33yarn add @tanstack/solid-query-devtools
34```
35​
36or
37​
38```sh
39bun add @tanstack/solid-query-devtools
40```
41​
42You can import the devtools like this:
43​
44```tsx
45import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
46```
47​
48By default, Solid Query Devtools are only enabled when `process.env.NODE_ENV === 'development'`. In production, the devtools components render nothing. During development, the server renders an empty container element and the devtools mount into it on the client.
49​
50## Floating Mode
51​
52Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
53​
54Place the following code as high in your Solid app as you can. The closer it is to the root of the page, the better it will work!
55​
56```tsx
57import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
58​
59function App() {
60 return (
61 <QueryClientProvider client={queryClient}>
62 {/* The rest of your application */}
63 <SolidQueryDevtools initialIsOpen={false} />
64 </QueryClientProvider>
65 )
67```
68​
69### Options
70​
71- `initialIsOpen: boolean`
72 - Set this `true` if you want the dev tools to default to being open
73- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
74 - Defaults to `bottom-right`
75 - The position of the TanStack logo to open and close the devtools panel
76- `position?: "top" | "bottom" | "left" | "right"`
77 - Defaults to `bottom`
78 - The position of the Solid Query devtools panel
79- `client?: QueryClient`,
80 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
81- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
82 - Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
83- `styleNonce?: string`
84 - 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.
85- `shadowDOMTarget?: ShadowRoot`
86 - Default behavior will apply the devtool's styles to the head tag within the DOM.
87 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.
88- `hideDisabledQueries?: boolean`
89 - Defaults to `false`.
90 - Set this to true to hide disabled queries from the devtools panel.
91- `theme?: "light" | "dark" | "system"`
92 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
93 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
94​
95## Embedded Mode
96​
97Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
98​
99Place the following code as high in your Solid app as you can. The closer it is to the root of the page, the better it will work!
100​
101```tsx
102import { createSignal, Show } from 'solid-js'
103import { SolidQueryDevtoolsPanel } from '@tanstack/solid-query-devtools'
104​
105function App() {
106 const [isOpen, setIsOpen] = createSignal(false)
107​
108 return (
109 <QueryClientProvider client={queryClient}>
110 {/* The rest of your application */}
111 <button
112 onClick={() => setIsOpen(!isOpen())}
113 >{`${isOpen() ? 'Close' : 'Open'} the devtools panel`}</button>
114 <Show when={isOpen()}>
115 <SolidQueryDevtoolsPanel onClose={() => setIsOpen(false)} />
116 </Show>
117 </QueryClientProvider>
118 )
120```
121​
122### Options
123​
124- `style?: JSX.CSSProperties`
125 - Custom styles for the devtools panel
126 - Default: `{ height: '100%', display: 'flex', 'flex-direction': 'column' }`
127 - The panel fills the height of its container, or is `500px` tall when the container has no set height.
128 - Example: `{ height: '100%' }`
129 - Example: `{ height: '100%', width: '100%' }`
130- `onClose?: () => void`
131 - Callback function that is called when the devtools panel is closed
132- `client?: QueryClient`,
133 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
134- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
135 - Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
136- `styleNonce?: string`
137 - 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.
138- `shadowDOMTarget?: ShadowRoot`
139 - Default behavior will apply the devtool's styles to the head tag within the DOM.
140 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.
141- `hideDisabledQueries?: boolean`
142 - Defaults to `false`.
143 - Set this to true to hide disabled queries from the devtools panel.
144- `theme?: "light" | "dark" | "system"`
145 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
146 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
147​
148## Filter queries and mutations
149​
150The **Filter** input above the query and mutation lists uses the **Key** scope by default. Select the scope button inside the input to switch between **Key**, **Data**, and **All**:
151​
152- **Key** matches the query hash, or the mutation key and submission time.
153- **Data** matches the query data, or the mutation variables or data, the same way **Search data** does below.
154- **All** matches either.
155​
156The selected scope is remembered across reloads, like the other filter settings.
157​
158## Search query and mutation data
159​
160Select a query or mutation and use **Search data** in its Data Explorer to search nested property names and primitive values. Search uses case-insensitive text matching and treats special characters as plain text.
161​
162Matching text is highlighted. Matching editable values have a highlighted input. The explorer opens matching branches and the first matching page in each paginated collection. Other pages with matches are highlighted so you can open them. You can still inspect other rows and edit query data.
163​
164The Data Explorer highlights up to 1,000 matches at a time.
165​
166Select **Clear** or press **Escape** in the search field to restore your manual expansion. Selecting another query or mutation clears the search, unless the filter scope is **Data** or **All**: then the search starts with the filter text. For a mutation, it starts only in the variables or data that match the filter.
167​
168## Devtools in production
169​
170Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
171​
172```tsx
173import { createSignal, lazy, onMount, Show, Suspense } from 'solid-js'
174import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
175import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
176import { Example } from './Example'
177​
178const queryClient = new QueryClient()
179​
180const SolidQueryDevtoolsProduction = lazy(() =>
181 import('@tanstack/solid-query-devtools/production').then((d) => ({
182 default: d.SolidQueryDevtools,
183 })),
185​
186function App() {
187 const [showDevtools, setShowDevtools] = createSignal(false)
188​
189 onMount(() => {
190 Object.assign(window, {
191 toggleDevtools: () => setShowDevtools((old) => !old),
192 })
193 })
194​
195 return (
196 <QueryClientProvider client={queryClient}>
197 <Example />
198 <SolidQueryDevtools initialIsOpen />
199 <Show when={showDevtools()}>
200 <Suspense fallback={null}>
201 <SolidQueryDevtoolsProduction />
202 </Suspense>
203 </Show>
204 </QueryClientProvider>
205 )
207​
208export default App
209```
210​
211With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
212​
213`@tanstack/solid-query-devtools/production` also exports `SolidQueryDevtoolsPanel` for Embedded Mode.
214​
215For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig.