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## Devtools in production
92β
93Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
94β
95```svelte
96<script lang="ts">
97 import { onMount } from 'svelte'
98 import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
99 import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
100 import Example from './Example.svelte'
101β
102 const queryClient = new QueryClient()
103β
104 let showDevtools = $state(false)
105β
106 onMount(() => {
107 Object.assign(window, {
108 toggleDevtools: () => (showDevtools = !showDevtools),
109 })
110 })
111</script>
112β
113<QueryClientProvider client={queryClient}>
114 <Example />
115 <SvelteQueryDevtools initialIsOpen />
116 {#if showDevtools}
117 {#await import('@tanstack/svelte-query-devtools/production') then { SvelteQueryDevtools: SvelteQueryDevtoolsProduction }}
118 <SvelteQueryDevtoolsProduction />
119 {/await}
120 {/if}
121</QueryClientProvider>
122```
123β
124With this, calling `window.toggleDevtools()` will download the devtools bundle and show them.
125β
126For TypeScript, you would need to set `moduleResolution` to `'bundler'`, `'node16'`, or `'nodenext'` in your tsconfig.