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" /> [Devtools for Chrome](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
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" /> [Devtools for Firefox](https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/)
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" /> [Devtools for Edge](https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj)
11β
12## Enable devtools
13β
14The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.
15β
16By default, Angular Query Devtools are only included in development mode bundles, so you don't need to worry about excluding them during a production build.
17β
18```ts
19import {
20 QueryClient,
21 provideTanStackQuery,
22} from '@tanstack/angular-query-experimental'
23β
24import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
25β
26export const appConfig: ApplicationConfig = {
27 providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
28}
29```
30β
31## Devtools in production
32β
33Devtools are automatically excluded from production builds. However, it might be desirable to lazy load the devtools in production.
34β
35To use `withDevtools` in production builds, import using the `production` sub-path. The function exported from the production subpath is identical to the main one, but won't be excluded from production builds.
36β
37```ts
38import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
39```
40β
41To control when devtools are loaded, you can use the `loadDevtools` option.
42β
43When not setting the option or setting it to 'auto', the devtools will be loaded automatically when Angular runs in development mode.
44β
45```ts
46import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
47β
48provideTanStackQuery(new QueryClient(), withDevtools())
49β
50// which is equivalent to
51provideTanStackQuery(
52 new QueryClient(),
53 withDevtools(() => ({ loadDevtools: 'auto' })),
54)
55```
56β
57When setting the option to true, the devtools will be loaded in both development and production mode.
58β
59This is useful if you want to load devtools based on [Angular environment configurations](https://angular.dev/tools/cli/environments). E.g. you could set this to true when the application is running on your production build staging environment.
60β
61```ts
62import { environment } from './environments/environment'
63// Make sure to use the production sub-path to load devtools in production builds
64import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
65β
66provideTanStackQuery(
67 new QueryClient(),
68 withDevtools(() => ({ loadDevtools: environment.loadDevtools })),
69)
70```
71β
72When setting the option to false, the devtools will not be loaded.
73β
74```ts
75provideTanStackQuery(
76 new QueryClient(),
77 withDevtools(() => ({ loadDevtools: false })),
78)
79```
80β
81## Derive options through reactivity
82β
83Options are passed to `withDevtools` from a callback function to support reactivity through signals. In the following example
84a signal is created from a RxJS observable that emits on a keyboard shortcut. When the derived signal is set to true, the devtools are lazily loaded.
85β
86> If you don't need devtools in production builds, don't use the `production` sub-path. Even though most of the devtools are lazy loaded on-demand, code is needed for on-demand loading and option handling. When importing devtools from `@tanstack/angular-query-experimental/devtools`, all devtools code will be excluded from your build and no lazy chunks will be created, minimizing deployment size.
87β
88The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed.
89β
90```ts
91import { Injectable, isDevMode } from '@angular/core'
92import { fromEvent, map, scan } from 'rxjs'
93import { toSignal } from '@angular/core/rxjs-interop'
94β
95@Injectable({ providedIn: 'root' })
96export class DevtoolsOptionsManager {
97 loadDevtools = toSignal(
98 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
99 map(
100 (event): boolean =>
101 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
102 ),
103 scan((acc, curr) => acc || curr, isDevMode()),
104 ),
105 {
106 initialValue: isDevMode(),
107 },
108 )
109}
110```
111β
112If you want to use an injectable such as a service in the callback you can use `deps`. The injected value will be passed as parameter to the callback function.
113β
114This is similar to `deps` in Angular's [`useFactory`](https://angular.dev/guide/di/dependency-injection-providers#factory-providers-usefactory) provider.
115β
116```ts
117// ...
118// π Note we import from the production sub-path to enable devtools lazy loading in production builds
119import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
120β
121export const appConfig: ApplicationConfig = {
122 providers: [
123 provideHttpClient(),
124 provideTanStackQuery(
125 new QueryClient(),
126 withDevtools(
127 (devToolsOptionsManager: DevtoolsOptionsManager) => ({
128 loadDevtools: devToolsOptionsManager.loadDevtools(),
129 }),
130 {
131 // `deps` is used to inject and pass `DevtoolsOptionsManager` to the `withDevtools` callback.
132 deps: [DevtoolsOptionsManager],
133 },
134 ),
135 ),
136 ],
137}
138```
139β
140### Options returned from the callback
141β
142Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
143β
144- `loadDevtools?: 'auto' | boolean`
145 - Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
146 - Use this to control if the devtools are loaded.
147- `initialIsOpen?: Boolean`
148 - Set this to `true` if you want the tools to default to being open
149- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
150 - Defaults to `bottom-right`
151 - The position of the TanStack logo to open and close the devtools panel
152 - If `relative`, the button is placed in the location that you render the devtools.
153- `position?: "top" | "bottom" | "left" | "right"`
154 - Defaults to `bottom`
155 - The position of the Angular Query devtools panel
156- `client?: QueryClient`,
157 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
158- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
159 - 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.
160- `styleNonce?: string`
161 - 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.
162- `shadowDOMTarget?: ShadowRoot`
163 - Default behavior will apply the devtool's styles to the head tag within the DOM.
164 - 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.
165- `hideDisabledQueries?: boolean`
166 - Set this to true to hide disabled queries from the devtools panel.