Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

devtools.md

168 lines6.5 KB

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​
14Add the devtools package (in addition to `@tanstack/angular-query-experimental`):
15​
16```bash
17npm install @tanstack/angular-query-devtools
18```
19​
20The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.
21​
22By default, Angular Query Devtools only load in development.
23​
24```ts
25import {
26 QueryClient,
27 provideTanStackQuery,
28} from '@tanstack/angular-query-experimental'
29​
30import { withDevtools } from '@tanstack/angular-query-devtools'
31​
32export const appConfig: ApplicationConfig = {
33 providers: [...provideTanStackQuery(new QueryClient(), withDevtools())],
35```
36​
37## Devtools in production
38​
39If you need the real implementation in production, import from the `production` entrypoint.
40​
41```ts
42import { withDevtools } from '@tanstack/angular-query-devtools/production'
43```
44​
45To control when devtools are loaded, use the `loadDevtools` option.
46​
47When omitted or set to `'auto'`, devtools only load in development mode.
48​
49```ts
50import { withDevtools } from '@tanstack/angular-query-devtools'
51​
52providers: [...provideTanStackQuery(new QueryClient(), withDevtools())]
53​
54// which is equivalent to
55providers: [
56 provideTanStackQuery(
57 new QueryClient(),
58 withDevtools(() => ({ loadDevtools: 'auto' })),
59 ),
61```
62​
63When setting the option to true, the devtools will be loaded in both development and production mode.
64​
65This 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.
66​
67```ts
68import { environment } from './environments/environment'
69// Make sure to use the production sub-path to load devtools in production builds
70import { withDevtools } from '@tanstack/angular-query-devtools/production'
71​
72providers: [
73 provideTanStackQuery(
74 new QueryClient(),
75 withDevtools(() => ({ loadDevtools: environment.loadDevtools })),
76 ),
78```
79​
80When setting the option to false, the devtools will not be loaded.
81​
82```ts
83providers: [
84 provideTanStackQuery(
85 new QueryClient(),
86 withDevtools(() => ({ loadDevtools: false })),
87 ),
89```
90​
91## Derive options through reactivity
92​
93Options can be returned from a callback so they can react to signals. For example, a signal derived from a keyboard shortcut can enable devtools on demand:
94​
95```ts
96import { Injectable, isDevMode } from '@angular/core'
97import { fromEvent, map, scan } from 'rxjs'
98import { toSignal } from '@angular/core/rxjs-interop'
99​
100@Injectable({ providedIn: 'root' })
101export class DevtoolsOptionsManager {
102 loadDevtools = toSignal(
103 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
104 map(
105 (event): boolean =>
106 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
107 ),
108 scan((acc, curr) => acc || curr, isDevMode()),
109 ),
110 {
111 initialValue: isDevMode(),
112 },
113 )
115```
116​
117To use an injectable such as a service in the callback, pass it through `deps`:
118​
119```ts
120// ...
121// πŸ‘‡ Note we import from the production sub-path to enable devtools lazy loading in production builds
122import { withDevtools } from '@tanstack/angular-query-devtools/production'
123​
124export const appConfig: ApplicationConfig = {
125 providers: [
126 provideHttpClient(),
127 provideTanStackQuery(
128 new QueryClient(),
129 withDevtools(
130 (devToolsOptionsManager: DevtoolsOptionsManager) => ({
131 loadDevtools: devToolsOptionsManager.loadDevtools(),
132 }),
133 {
134 deps: [DevtoolsOptionsManager],
135 },
136 ),
137 ),
138 ],
140```
141​
142### Options returned from the callback
143​
144Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
145​
146- `loadDevtools?: 'auto' | boolean`
147 - Omit or `'auto'`: load devtools only in development mode.
148 - Use this to control whether devtools load when using the `/production` import.
149- `initialIsOpen?: Boolean`
150 - Set this to `true` if you want the tools to default to being open
151- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
152 - Defaults to `bottom-right`
153 - The position of the TanStack logo to open and close the devtools panel
154 - If `relative`, the button is placed in the location that you render the devtools.
155- `position?: "top" | "bottom" | "left" | "right"`
156 - Defaults to `bottom`
157 - The position of the Angular Query devtools panel
158- `client?: QueryClient`,
159 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
160- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
161 - 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.
162- `styleNonce?: string`
163 - 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.
164- `shadowDOMTarget?: ShadowRoot`
165 - Default behavior will apply the devtool's styles to the head tag within the DOM.
166 - 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.
167- `hideDisabledQueries?: boolean`
168 - Set this to true to hide disabled queries from the devtools panel.