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

devtools.md

138 lines6.1 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" /> [Devtools for Chrome](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
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" /> [Devtools for Firefox](https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/)
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" /> [Devtools for Edge](https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj)
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```bash
24npm i @tanstack/vue-query-devtools
25```
26​
27or
28​
29```bash
30pnpm add @tanstack/vue-query-devtools
31```
32​
33or
34​
35```bash
36yarn add @tanstack/vue-query-devtools
37```
38​
39or
40​
41```bash
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"`
69 - Defaults to `bottom-right`.
70 - The position of the React Query logo to open and close the devtools panel.
71- `position?: "top" | "bottom" | "left" | "right"`
72 - Defaults to `bottom`.
73 - The position of the React 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 - 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.
80- `shadowDOMTarget?: ShadowRoot`
81 - Default behavior will apply the devtool's styles to the head tag within the DOM.
82 - 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.
83​
84## Embedded Mode
85​
86Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
87​
88Place the following code as high in your React app as you can. The closer it is to the root of the page, the better it will work!
89​
90```vue
91<script setup>
92import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
93const isDevtoolsOpen = ref(false)
94function toggleDevtools() {
95 isDevtoolsOpen.value = !isDevtoolsOpen.value
97</script>
98​
99<template>
100 <h1>The app!</h1>
101 <button @click="toggleDevtools">Open Devtools</button>
102 <VueQueryDevtoolsPanel v-if="isDevtoolsOpen" :onClose="toggleDevtools" />
103</template>
104```
105​
106### Options
107​
108- `style?: React.CSSProperties`
109 - Custom styles for the devtools panel
110 - Default: `{ height: '500px' }`
111 - Example: `{ height: '100%' }`
112 - Example: `{ height: '100%', width: '100%' }`
113- `onClose?: () => unknown`
114 - Callback function that is called when the devtools panel is closed
115- `client?: QueryClient`,
116 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
117- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
118 - 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.
119- `styleNonce?: string`
120 - 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.
121- `shadowDOMTarget?: ShadowRoot`
122 - Default behavior will apply the devtool's styles to the head tag within the DOM.
123 - 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.
124​
125## Traditional Devtools
126​
127Vue Query will seamlessly integrate with the [Official Vue devtools](https://github.com/vuejs/devtools-next), adding custom inspector and timeline events.
128Devtool code will be treeshaken from production bundles by default.
129​
130To make it work, you only need to enable it in the plugin options:
131​
132```ts
133app.use(VueQueryPlugin, {
134 enableDevtoolsV6Plugin: true,
135})
136```
137​
138Both v6 and v7 versions of devtools are supported.