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:
Install and Import the Devtools#
The devtools are a separate package that you need to install:
npm i @tanstack/svelte-query-devtools
or
pnpm add @tanstack/svelte-query-devtools
or
yarn add @tanstack/svelte-query-devtools
or
bun add @tanstack/svelte-query-devtools
You can import the devtools like this:
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
By default, Svelte Query Devtools are only rendered in development, using DEV from esm-env. In production, the devtools component renders nothing.
Floating Mode#
Floating 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.
Place 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!
<script>
import { QueryClientProvider } from '@tanstack/svelte-query'
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
</script>
<QueryClientProvider client={queryClient}>
{/* The rest of your application */}
<SvelteQueryDevtools />
</QueryClientProvider>
Options#
initialIsOpen: boolean- Set this
trueif you want the dev tools to default to being open
- Set this
buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"- Defaults to
bottom-right - The position of the TanStack logo to open and close the devtools panel
- If
relative, the button is placed in the location that you render the devtools.
- Defaults to
position?: "top" | "bottom" | "left" | "right"- Defaults to
bottom - The position of the Svelte Query devtools panel
- Defaults to
client?: QueryClient,- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
errorTypes?: { name: string; initializer: (query: Query) => TError}[]- 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.
styleNonce?: string- Deprecated. The devtools no longer add a
<style>element, so they need no nonce. This option does nothing.
- Deprecated. The devtools no longer add a
shadowDOMTarget?: ShadowRoot- 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.
trustedTypesPolicy?: { createHTML: (html: string) => unknown }- 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 exampletrustedTypes.createPolicy('devtools', { createHTML: (html) => html }).
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces
hideDisabledQueries?: boolean- Defaults to
false. - Set this to true to hide disabled queries from the devtools panel.
- Defaults to
theme?: Theme- Defaults to the theme selected in the devtools Settings menu, or
systemif none is selected. - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
- Defaults to the theme selected in the devtools Settings menu, or
Filter queries and mutations#
The 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:
- Key matches the query hash, or the mutation key and submission time.
- Data matches the query data, or the mutation variables or data, the same way Search data does below.
- All matches either.
The selected scope is remembered across reloads, like the other filter settings.
Search query and mutation data#
Select 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.
Matching 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.
The Data Explorer highlights up to 1,000 matches at a time.
Select 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.
Devtools in production#
Devtools are excluded in production builds. However, it might be desirable to lazy load the devtools in production:
<script lang="ts">
import { onMount } from 'svelte'
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
import Example from './Example.svelte'
const queryClient = new QueryClient()
let showDevtools = $state(false)
onMount(() => {
Object.assign(window, {
toggleDevtools: () => (showDevtools = !showDevtools),
})
})
</script>
<QueryClientProvider client={queryClient}>
<Example />
<SvelteQueryDevtools initialIsOpen />
{#if showDevtools}
{#await import('@tanstack/svelte-query-devtools/production') then { SvelteQueryDevtools: SvelteQueryDevtoolsProduction }}
<SvelteQueryDevtoolsProduction />
{/await}
{/if}
</QueryClientProvider>
With this, calling window.toggleDevtools() will download the devtools bundle and show them.
For TypeScript, you would need to set moduleResolution to 'bundler', 'node16', or 'nodenext' in your tsconfig.