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

devtools.md

217 lines10.6 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 - Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
85- `shadowDOMTarget?: ShadowRoot`
86 - The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
87- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
88 - The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`. The devtools bundle their own Solid runtime, so this is separate from the policy your app sets with `setTrustedTypesPolicy` from `solid-js/web` (1.9.20+).
89- `hideDisabledQueries?: boolean`
90 - Defaults to `false`.
91 - Set this to true to hide disabled queries from the devtools panel.
92- `theme?: "light" | "dark" | "system"`
93 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
94 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
95​
96## Embedded Mode
97​
98Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
99​
100Place 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!
101​
102```tsx
103import { SolidQueryDevtoolsPanel } from '@tanstack/solid-query-devtools'
104import { createSignal, Show } from 'solid-js'
105​
106function App() {
107 const [isOpen, setIsOpen] = createSignal(false)
108​
109 return (
110 <QueryClientProvider client={queryClient}>
111 {/* The rest of your application */}
112 <button
113 onClick={() => setIsOpen(!isOpen())}
114 >{`${isOpen() ? 'Close' : 'Open'} the devtools panel`}</button>
115 <Show when={isOpen()}>
116 <SolidQueryDevtoolsPanel onClose={() => setIsOpen(false)} />
117 </Show>
118 </QueryClientProvider>
119 )
121```
122​
123### Options
124​
125- `style?: JSX.CSSProperties`
126 - Custom styles for the devtools panel
127 - Default: `{ height: '100%', display: 'flex', 'flex-direction': 'column' }`
128 - The panel fills the height of its container, or is `500px` tall when the container has no set height.
129 - Example: `{ height: '100%' }`
130 - Example: `{ height: '100%', width: '100%' }`
131- `onClose?: () => void`
132 - Callback function that is called when the devtools panel is closed
133- `client?: QueryClient`,
134 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
135- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
136 - 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.
137- `styleNonce?: string`
138 - Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
139- `shadowDOMTarget?: ShadowRoot`
140 - The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
141- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
142 - The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`. The devtools bundle their own Solid runtime, so this is separate from the policy your app sets with `setTrustedTypesPolicy` from `solid-js/web` (1.9.20+).
143- `hideDisabledQueries?: boolean`
144 - Defaults to `false`.
145 - Set this to true to hide disabled queries from the devtools panel.
146- `theme?: "light" | "dark" | "system"`
147 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
148 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
149​
150## Filter queries and mutations
151​
152The **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**:
153​
154- **Key** matches the query hash, or the mutation key and submission time.
155- **Data** matches the query data, or the mutation variables or data, the same way **Search data** does below.
156- **All** matches either.
157​
158The selected scope is remembered across reloads, like the other filter settings.
159​
160## Search query and mutation data
161​
162Select 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.
163​
164Matching 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.
165​
166The Data Explorer highlights up to 1,000 matches at a time.
167​
168Select **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.
169​
170## Devtools in production
171​
172Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
173​
174```tsx
175import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
176import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
177import { createSignal, lazy, onMount, Show, Suspense } from 'solid-js'
178import { Example } from './Example'
179​
180const queryClient = new QueryClient()
181​
182const SolidQueryDevtoolsProduction = lazy(() =>
183 import('@tanstack/solid-query-devtools/production').then((d) => ({
184 default: d.SolidQueryDevtools,
185 })),
187​
188function App() {
189 const [showDevtools, setShowDevtools] = createSignal(false)
190​
191 onMount(() => {
192 Object.assign(window, {
193 toggleDevtools: () => setShowDevtools((old) => !old),
194 })
195 })
196​
197 return (
198 <QueryClientProvider client={queryClient}>
199 <Example />
200 <SolidQueryDevtools initialIsOpen />
201 <Show when={showDevtools()}>
202 <Suspense fallback={null}>
203 <SolidQueryDevtoolsProduction />
204 </Suspense>
205 </Show>
206 </QueryClientProvider>
207 )
209​
210export default App
211```
212​
213With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
214​
215`@tanstack/solid-query-devtools/production` also exports `SolidQueryDevtoolsPanel` for Embedded Mode.
216​
217For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig.