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

devtools.md

209 lines9.9 KB

1---
2id: devtools
3title: Devtools
4---
5​
6Wave your hands in the air and shout hooray because Vue Query comes with dedicated devtools! πŸ₯³
7​
8When you begin your Vue Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of Vue 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## Component based Devtools (Vue 3)
17​
18You can directly integrate the devtools component into your page using a dedicated package.
19Component-based devtools use a framework-agnostic implementation and are always up-to-date.
20​
21The devtools component is a separate package that you need to install:
22​
23```sh
24npm i @tanstack/vue-query-devtools
25```
26​
27or
28​
29```sh
30pnpm add @tanstack/vue-query-devtools
31```
32​
33or
34​
35```sh
36yarn add @tanstack/vue-query-devtools
37```
38​
39or
40​
41```sh
42bun add @tanstack/vue-query-devtools
43```
44​
45By default, Vue Query Devtools are only included in bundles when `process.env.NODE_ENV === 'development'`, so you don't need to worry about excluding them during a production build.
46​
47## Floating Mode
48​
49Devtools will be mounted 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.
50​
51Place the following code as high in your Vue app as you can. The closer it is to the root of the page, the better it will work!
52​
53```vue
54<script setup>
55import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
56</script>
57​
58<template>
59 <h1>The app!</h1>
60 <VueQueryDevtools />
61</template>
62```
63​
64### Options
65​
66- `initialIsOpen: boolean`
67 - Set this `true` if you want the dev tools to default to being open.
68- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
69 - Defaults to `bottom-right`.
70 - The position of the TanStack logo to open and close the devtools panel.
71- `position?: "top" | "bottom" | "left" | "right"`
72 - Defaults to `bottom`.
73 - The position of the Vue Query devtools panel.
74- `client?: QueryClient`
75 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
76- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
77 - Use this to predefine some errors that can be triggered on your queries. The initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
78- `styleNonce?: string`
79 - Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
80- `shadowDOMTarget?: ShadowRoot`
81 - 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.
82- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
83 - 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 })`.
84- `hideDisabledQueries?: boolean`
85 - Defaults to `false`.
86 - Set this to true to hide disabled queries from the devtools panel.
87- `theme?: "light" | "dark" | "system"`
88 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
89 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
90​
91## Embedded Mode
92​
93Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
94​
95Place the following code as high in your Vue app as you can. The closer it is to the root of the page, the better it will work!
96​
97```vue
98<script setup>
99import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
100import { ref } from 'vue'
101​
102const isOpen = ref(false)
103</script>
104​
105<template>
106 <h1>The app!</h1>
107 <button @click="isOpen = !isOpen">
108 {{ isOpen ? 'Close' : 'Open' }} the devtools panel
109 </button>
110 <VueQueryDevtoolsPanel v-if="isOpen" :onClose="() => (isOpen = false)" />
111</template>
112```
113​
114### Options
115​
116- `style?: Partial<CSSStyleDeclaration>`
117 - Custom styles for the devtools panel
118 - Default: `{ height: '100%', display: 'flex', flexDirection: 'column' }`
119 - The panel fills the height of its container, or is `500px` tall when the container has no set height.
120 - Example: `{ height: '100%' }`
121 - Example: `{ height: '100%', width: '100%' }`
122- `onClose?: () => void`
123 - Callback function that is called when the devtools panel is closed
124- `client?: QueryClient`,
125 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
126- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
127 - 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.
128- `styleNonce?: string`
129 - Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
130- `shadowDOMTarget?: ShadowRoot`
131 - 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.
132- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
133 - 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 })`.
134- `hideDisabledQueries?: boolean`
135 - Defaults to `false`.
136 - Set this to true to hide disabled queries from the devtools panel.
137- `theme?: "light" | "dark" | "system"`
138 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
139 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
140​
141## Filter queries and mutations
142​
143The **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**:
144​
145- **Key** matches the query hash, or the mutation key and submission time.
146- **Data** matches the query data, or the mutation variables or data, the same way **Search data** does below.
147- **All** matches either.
148​
149The selected scope is remembered across reloads, like the other filter settings.
150​
151## Search query and mutation data
152​
153Select 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.
154​
155Matching 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.
156​
157The Data Explorer highlights up to 1,000 matches at a time.
158​
159Select **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.
160​
161## Devtools in production
162​
163Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
164​
165```vue
166<script setup>
167import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
168import { defineAsyncComponent, onMounted, ref } from 'vue'
169​
170const VueQueryDevtoolsProduction = defineAsyncComponent(() =>
171 import('@tanstack/vue-query-devtools/production').then(
172 (d) => d.VueQueryDevtools,
173 ),
175​
176const showDevtools = ref(false)
177​
178onMounted(() => {
179 Object.assign(window, {
180 toggleDevtools: () => (showDevtools.value = !showDevtools.value),
181 })
182})
183</script>
184​
185<template>
186 <h1>The app!</h1>
187 <VueQueryDevtools initialIsOpen />
188 <VueQueryDevtoolsProduction v-if="showDevtools" />
189</template>
190```
191​
192With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
193​
194For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig.
195​
196## Traditional Devtools
197​
198Vue Query will seamlessly integrate with the [Official Vue devtools](https://github.com/vuejs/devtools-next), adding custom inspector and timeline events.
199Devtool code will be treeshaken from production bundles by default.
200​
201To make it work, you only need to enable it in the plugin options:
202​
203```ts
204app.use(VueQueryPlugin, {
205 enableDevtoolsV6Plugin: true,
206})
207```
208​
209Both v6 and v7 versions of devtools are supported.