Open History to see the last commit
1---
2id: devtools
3title: Devtools
4---
5β
6> 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:
7>
8> - <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>
9> - <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>
10> - <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>
11β
12## Install and Import the Devtools
13β
14The devtools are a separate package that you need to install:
15β
16```sh
17npm i @tanstack/svelte-query-devtools
18```
19β
20or
21β
22```sh
23pnpm add @tanstack/svelte-query-devtools
24```
25β
26or
27β
28```sh
29yarn add @tanstack/svelte-query-devtools
30```
31β
32or
33β
34```sh
35bun add @tanstack/svelte-query-devtools
36```
37β
38You can import the devtools like this:
39β
40```ts
41import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
42```
43β
44By default, Svelte Query Devtools are only rendered in development, using `DEV` from `esm-env`. In production, the devtools component renders nothing.
45β
46## Floating Mode
47β
48Floating 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.
49β
50Place the following code as high in your Svelte app as you can. The closer it is to the root of the page, the better it will work!
51β
52```ts
53<script>
54 import { QueryClientProvider } from '@tanstack/svelte-query'
55 import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
56</script>
57β
58<QueryClientProvider client={queryClient}>
59 {/* The rest of your application */}
60 <SvelteQueryDevtools />
61</QueryClientProvider>
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 - If `relative`, the button is placed in the location that you render the devtools.
72- `position?: "top" | "bottom" | "left" | "right"`
73 - Defaults to `bottom`
74 - The position of the Svelte Query devtools panel
75- `client?: QueryClient`,
76 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
77- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
78 - 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.
79- `styleNonce?: string`
80 - 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.
81- `shadowDOMTarget?: ShadowRoot`
82 - Default behavior will apply the devtool's styles to the head tag within the DOM.
83 - 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.
84- `hideDisabledQueries?: boolean`
85 - Defaults to `false`.
86 - Set this to true to hide disabled queries from the devtools panel.
87- `theme?: Theme`
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## Filter queries and mutations
92β
93The **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**:
94β
95- **Key** matches the query hash, or the mutation key and submission time.
96- **Data** matches the query data, or the mutation variables or data, the same way **Search data** does below.
97- **All** matches either.
98β
99The selected scope is remembered across reloads, like the other filter settings.
100β
101## Search query and mutation data
102β
103Select 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.
104β
105Matching 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.
106β
107The Data Explorer highlights up to 1,000 matches at a time.
108β
109Select **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.
110β
111## Devtools in production
112β
113Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
114β
115```svelte
116<script lang="ts">
117 import { onMount } from 'svelte'
118 import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
119 import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
120 import Example from './Example.svelte'
121β
122 const queryClient = new QueryClient()
123β
124 let showDevtools = $state(false)
125β
126 onMount(() => {
127 Object.assign(window, {
128 toggleDevtools: () => (showDevtools = !showDevtools),
129 })
130 })
131</script>
132β
133<QueryClientProvider client={queryClient}>
134 <Example />
135 <SvelteQueryDevtools initialIsOpen />
136 {#if showDevtools}
137 {#await import('@tanstack/svelte-query-devtools/production') then { SvelteQueryDevtools: SvelteQueryDevtoolsProduction }}
138 <SvelteQueryDevtoolsProduction />
139 {/await}
140 {/if}
141</QueryClientProvider>
142```
143β
144With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
145β
146For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig.