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## 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 only 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β
86The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed.
87β
88```ts
89import { Injectable, isDevMode } from '@angular/core'
90import { fromEvent, map, scan } from 'rxjs'
91import { toSignal } from '@angular/core/rxjs-interop'
92β
93@Injectable({ providedIn: 'root' })
94export class DevtoolsOptionsManager {
95 loadDevtools = toSignal(
96 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
97 map(
98 (event): boolean =>
99 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
100 ),
101 scan((acc, curr) => acc || curr, isDevMode()),
102 ),
103 {
104 initialValue: isDevMode(),
105 },
106 )
107}
108```
109β
110If 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.
111β
112This is similar to `deps` in Angular's [`useFactory`](https://angular.dev/guide/di/dependency-injection-providers#factory-providers-usefactory) provider.
113β
114```ts
115// ...
116// π Note we import from the production sub-path to enable devtools lazy loading in production builds
117import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
118β
119export const appConfig: ApplicationConfig = {
120 providers: [
121 provideHttpClient(),
122 provideTanStackQuery(
123 new QueryClient(),
124 withDevtools(
125 (devToolsOptionsManager: DevtoolsOptionsManager) => ({
126 loadDevtools: devToolsOptionsManager.loadDevtools(),
127 }),
128 {
129 // `deps` is used to inject and pass `DevtoolsOptionsManager` to the `withDevtools` callback.
130 deps: [DevtoolsOptionsManager],
131 },
132 ),
133 ),
134 ],
135}
136```
137β
138### Options returned from the callback
139β
140Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, `initialIsOpen`, and `theme` support reactivity through signals.
141β
142- `loadDevtools?: 'auto' | boolean`
143 - Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
144 - Use this to control if the devtools are loaded.
145- `initialIsOpen?: Boolean`
146 - Set this to `true` if you want the tools to default to being open
147- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
148 - Defaults to `bottom-right`
149 - The position of the TanStack logo to open and close the devtools panel
150 - If `relative`, the button is placed in the location that you render the devtools.
151- `position?: "top" | "bottom" | "left" | "right"`
152 - Defaults to `bottom`
153 - The position of the Angular Query devtools panel
154- `client?: QueryClient`,
155 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
156- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
157 - 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.
158- `styleNonce?: string`
159 - 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.
160- `shadowDOMTarget?: ShadowRoot`
161 - Default behavior will apply the devtool's styles to the head tag within the DOM.
162 - 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.
163- `hideDisabledQueries?: boolean`
164 - Defaults to `false`.
165 - Set this to true to hide disabled queries from the devtools panel.
166- `theme?: "light" | "dark" | "system"`
167 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
168 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.
169β
170## Embedded Mode
171β
172Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.
173β
174Use `injectDevtoolsPanel` to render the devtools panel inside an element of your component. Like `withDevtools`, it is only included in development mode bundles. To use it in production builds, import it from `@tanstack/angular-query-experimental/devtools-panel/production`.
175β
176```angular-ts
177import { Component, signal, viewChild } from '@angular/core'
178import { injectDevtoolsPanel } from '@tanstack/angular-query-experimental/devtools-panel'
179import type { ElementRef } from '@angular/core'
180β
181@Component({
182 selector: 'app-root',
183 template: `
184 <button type="button" (click)="isOpen.set(!isOpen())">
185 {{ isOpen() ? 'Close' : 'Open' }} the devtools panel
186 </button>
187 @if (isOpen()) {
188 <div #div style="height: 500px"></div>
189 }
190 `,
191})
192export class AppComponent {
193 readonly isOpen = signal(false)
194 readonly divEl = viewChild<ElementRef>('div')
195β
196 readonly devtools = injectDevtoolsPanel(() => ({
197 hostElement: this.divEl(),
198 onClose: () => this.isOpen.set(false),
199 }))
200}
201```
202β
203`injectDevtoolsPanel` must be called in an injection context, or be given an `Injector` through the `injector` option in its second argument: `injectDevtoolsPanel(() => ({ ... }), { injector })`.
204β
205### Options
206β
207Of these options `hostElement`, `client`, `errorTypes`, `onClose`, and `theme` support reactivity through signals.
208β
209- `hostElement?: ElementRef`
210 - The element to render the devtools panel in. When it is `undefined` or `null`, the devtools panel is not created, or is destroyed if it exists.
211- `onClose?: () => void`
212 - Callback function that is called when the devtools panel is closed
213- `client?: QueryClient`,
214 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
215- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
216 - 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.
217- `styleNonce?: string`
218 - 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.
219- `shadowDOMTarget?: ShadowRoot`
220 - Default behavior will apply the devtool's styles to the head tag within the DOM.
221 - 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.
222- `hideDisabledQueries?: boolean`
223 - Defaults to `false`.
224 - Set this to true to hide disabled queries from the devtools panel.
225- `theme?: "light" | "dark" | "system"`
226 - Defaults to the theme selected in the devtools Settings menu, or `system` if none is selected.
227 - Set this to change the theme of the devtools panel. This overrides the theme selected in the Settings menu.