Open History to see the last commit
1---
2id: devtools
3title: Devtools
4---
5β
6> For Google Chrome users: A third-party Chrome extension is available for debugging TanStack Query directly in Chrome DevTools. This provides the same functionality as the framework-specific devtools packages. Check it out here: [TanStack Query DevTools](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
7β
8## Enable devtools
9β
10The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.
11β
12By 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.
13β
14```ts
15import {
16 QueryClient,
17 provideTanStackQuery,
18} from '@tanstack/angular-query-experimental'
19β
20import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
21β
22export const appConfig: ApplicationConfig = {
23 providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
24}
25```
26β
27## Devtools in production
28β
29Devtools are automatically excluded from production builds. However, it might be desirable to lazy load the devtools in production.
30β
31To 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.
32β
33```ts
34import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
35```
36β
37To control when devtools are loaded, you can use the `loadDevtools` option.
38β
39When not setting the option or setting it to 'auto', the devtools will be loaded automatically when Angular runs in development mode.
40β
41```ts
42import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
43β
44provideTanStackQuery(new QueryClient(), withDevtools())
45β
46// which is equivalent to
47provideTanStackQuery(
48 new QueryClient(),
49 withDevtools(() => ({ loadDevtools: 'auto' })),
50)
51```
52β
53When setting the option to true, the devtools will be loaded in both development and production mode.
54β
55This 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.
56β
57```ts
58import { environment } from './environments/environment'
59// Make sure to use the production sub-path to load devtools in production builds
60import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
61β
62provideTanStackQuery(
63 new QueryClient(),
64 withDevtools(() => ({ loadDevtools: environment.loadDevtools })),
65)
66```
67β
68When setting the option to false, the devtools will not be loaded.
69β
70```ts
71provideTanStackQuery(
72 new QueryClient(),
73 withDevtools(() => ({ loadDevtools: false })),
74)
75```
76β
77## Derive options through reactivity
78β
79Options are passed to `withDevtools` from a callback function to support reactivity through signals. In the following example
80a 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.
81β
82> 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.
83β
84The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed.
85β
86```ts
87import { Injectable, isDevMode } from '@angular/core'
88import { fromEvent, map, scan } from 'rxjs'
89import { toSignal } from '@angular/core/rxjs-interop'
90β
91@Injectable({ providedIn: 'root' })
92export class DevtoolsOptionsManager {
93 loadDevtools = toSignal(
94 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
95 map(
96 (event): boolean =>
97 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
98 ),
99 scan((acc, curr) => acc || curr, isDevMode()),
100 ),
101 {
102 initialValue: isDevMode(),
103 },
104 )
105}
106```
107β
108If 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.
109β
110This is similar to `deps` in Angular's [`useFactory`](https://angular.dev/guide/di/dependency-injection-providers#factory-providers-usefactory) provider.
111β
112```ts
113// ...
114// π Note we import from the production sub-path to enable devtools lazy loading in production builds
115import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
116β
117export const appConfig: ApplicationConfig = {
118 providers: [
119 provideHttpClient(),
120 provideTanStackQuery(
121 new QueryClient(),
122 withDevtools(
123 (devToolsOptionsManager: DevtoolsOptionsManager) => ({
124 loadDevtools: devToolsOptionsManager.loadDevtools(),
125 }),
126 {
127 // `deps` is used to inject and pass `DevtoolsOptionsManager` to the `withDevtools` callback.
128 deps: [DevtoolsOptionsManager],
129 },
130 ),
131 ),
132 ],
133}
134```
135β
136### Options returned from the callback
137β
138Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
139β
140- `loadDevtools?: 'auto' | boolean`
141 - Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
142 - Use this to control if the devtools are loaded.
143- `initialIsOpen?: Boolean`
144 - Set this to `true` if you want the tools to default to being open
145- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
146 - Defaults to `bottom-right`
147 - The position of the TanStack logo to open and close the devtools panel
148 - If `relative`, the button is placed in the location that you render the devtools.
149- `position?: "top" | "bottom" | "left" | "right"`
150 - Defaults to `bottom`
151 - The position of the Angular Query devtools panel
152- `client?: QueryClient`,
153 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
154- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
155 - 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.
156- `styleNonce?: string`
157 - 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.
158- `shadowDOMTarget?: ShadowRoot`
159 - Default behavior will apply the devtool's styles to the head tag within the DOM.
160 - 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.
161- `hideDisabledQueries?: boolean`
162 - Set this to true to hide disabled queries from the devtools panel.