Skip to content

feat(angular-query): move devtools to conditional sub-paths #9270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'package: angular-query-devtools-experimental':
- 'packages/angular-query-devtools-experimental/**/*'
'package: angular-query-experimental':
- 'packages/angular-query-experimental/**/*'
'package: eslint-plugin-query':
Expand Down
4 changes: 0 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ comment:

component_management:
individual_components:
- component_id: angular-query-devtools-experimental
name: '@tanstack/angular-query-devtools-experimental'
paths:
- packages/angular-query-devtools-experimental/**
- component_id: angular-query-experimental
name: '@tanstack/angular-query-experimental'
paths:
Expand Down
73 changes: 56 additions & 17 deletions docs/framework/angular/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,38 @@ title: Devtools

The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.

By default, the devtools are enabled when Angular [`isDevMode`](https://angular.dev/api/core/isDevMode) returns true. So you don't need to worry about excluding them during a production build. The core tools are lazily loaded and excluded from bundled code. In most cases, all you'll need to do is add `withDevtools()` to `provideTanStackQuery` without any additional configuration.
By 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.

```ts
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'

import { withDevtools } from '@tanstack/angular-query-experimental/devtools'

export const appConfig: ApplicationConfig = {
providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
}
```

## Configuring if devtools are loaded
## Devtools in production

Devtools are automatically excluded from production builds. However, it might be desirable to lazy load the devtools in production.

To 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.

```ts
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
```

If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.
To control when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations or user interaction. For instance, you might have a test environment running in production mode but still require devtools to be available.

When not setting the option or setting it to 'auto', the devtools will be loaded when Angular is in development mode.
When not setting the option or setting it to 'auto', the devtools will be loaded automatically when Angular runs in development mode.

```ts
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'

provideTanStackQuery(new QueryClient(), withDevtools())

// which is equivalent to
Expand All @@ -39,7 +50,12 @@ provideTanStackQuery(

When setting the option to true, the devtools will be loaded in both development and production mode.

This is particularly useful if you want to load devtools based on environment configurations. E.g. you could set this to true either when `isDevMode()` is true or when the application is running on your production build staging environment.

```ts
// Make sure to use the production sub-path to load devtools in production builds
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'

provideTanStackQuery(
new QueryClient(),
withDevtools(() => ({ loadDevtools: true })),
Expand All @@ -55,44 +71,67 @@ provideTanStackQuery(
)
```

The `withDevtools` options are returned from a callback function to support reactivity through signals. In the following example
a signal is created from a RxJS observable that listens for a keyboard shortcut. When the event is triggered, the devtools are lazily loaded.
Using this technique allows you to support on-demand loading of the devtools even in production mode, without including the full tools in the bundled code.
## Derive options through reactivity

Options are passed to `withDevtools` from a callback function to support reactivity through signals. In the following example
a 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.

> 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.

The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed.

```ts
import { Injectable, isDevMode } from '@angular/core'
import { fromEvent, map, scan } from 'rxjs'
import { toSignal } from '@angular/core/rxjs-interop'

@Injectable({ providedIn: 'root' })
class DevtoolsOptionsManager {
export class DevtoolsOptionsManager {
loadDevtools = toSignal(
fromEvent<KeyboardEvent>(document, 'keydown').pipe(
map(
(event): boolean =>
event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
),
scan((acc, curr) => acc || curr, false),
scan((acc, curr) => acc || curr, isDevMode()),
),
{
initialValue: false,
initialValue: isDevMode(),
},
)
}
```

If 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.

This is similar to `deps` in Angular's [`useFactory`](https://angular.dev/guide/di/dependency-injection-providers#factory-providers-usefactory) provider.

```ts
// ...
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'

export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideTanStackQuery(
new QueryClient(),
withDevtools(() => ({
initialIsOpen: true,
loadDevtools: inject(DevtoolsOptionsManager).loadDevtools(),
})),
withDevtools(
(devToolsOptionsManager: DevtoolsOptionsManager) => ({
loadDevtools: devToolsOptionsManager.loadDevtools(),
}),
{
// `deps` is used to inject and pass `DevtoolsOptionsManager` to the `withDevtools` callback.
deps: [DevtoolsOptionsManager],
},
),
),
],
}
```

### Options
### Options returned from the callback

Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.

- `loadDevtools?: 'auto' | boolean`
- Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/angular/reference/functions/withdevtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: withDevtools
# Function: withDevtools()

```ts
function withDevtools(withDevtoolsFn?): DeveloperToolsFeature
function withDevtools(withDevtoolsFn?): DevtoolsFeature
```

Enables developer tools.
Expand Down Expand Up @@ -35,7 +35,7 @@ A function that returns `DevtoolsOptions`.

## Returns

[`DeveloperToolsFeature`](../../type-aliases/developertoolsfeature.md)
[`DevtoolsFeature`](../../type-aliases/developertoolsfeature.md)

A set of providers for use with `provideTanStackQuery`.

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/angular/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ title: '@tanstack/angular-query-experimental'
- [DefinedCreateQueryResult](../type-aliases/definedcreatequeryresult.md)
- [DefinedInitialDataInfiniteOptions](../type-aliases/definedinitialdatainfiniteoptions.md)
- [DefinedInitialDataOptions](../type-aliases/definedinitialdataoptions.md)
- [DeveloperToolsFeature](../type-aliases/developertoolsfeature.md)
- [DevtoolsFeature](../type-aliases/developertoolsfeature.md)
- [PersistQueryClientFeature](../type-aliases/persistqueryclientfeature.md)
- [QueriesOptions](../type-aliases/queriesoptions.md)
- [QueriesResults](../type-aliases/queriesresults.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
id: DeveloperToolsFeature
title: DeveloperToolsFeature
id: DevtoolsFeature
title: DevtoolsFeature
---

# Type Alias: DeveloperToolsFeature
# Type Alias: DevtoolsFeature

```ts
type DeveloperToolsFeature = QueryFeature<'DeveloperTools'>
type DevtoolsFeature = QueryFeature<'DeveloperTools'>
```

A type alias that represents a feature which enables developer tools.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: QueryFeatures
# Type Alias: QueryFeatures

```ts
type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature
type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature
```

A type alias that represents all Query features available for use with `provideTanStackQuery`.
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/auto-refetching/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { mockInterceptor } from './interceptor/mock-api.interceptor'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/basic-persister/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { provideHttpClient, withFetch } from '@angular/common/http'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import type { ApplicationConfig } from '@angular/core'

const localStoragePersister = createSyncStoragePersister({
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/basic/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { provideHttpClient, withFetch } from '@angular/common/http'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import type { ApplicationConfig } from '@angular/core'

export const appConfig: ApplicationConfig = {
Expand Down
1 change: 0 additions & 1 deletion examples/angular/devtools-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@angular/platform-browser": "^20.0.0",
"@angular/platform-browser-dynamic": "^20.0.0",
"@angular/router": "^20.0.0",
"@tanstack/angular-query-devtools-experimental": "^5.80.8",
"@tanstack/angular-query-experimental": "^5.80.8",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
signal,
viewChild,
} from '@angular/core'
import { injectDevtoolsPanel } from '@tanstack/angular-query-devtools-experimental'
import { injectDevtoolsPanel } from '@tanstack/angular-query-experimental/devtools-panel'
import { ExampleQueryComponent } from './example-query.component'
import type { ElementRef } from '@angular/core'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@angular/core'
import { ExampleQueryComponent } from './example-query.component'
import type { ElementRef } from '@angular/core'
import type { DevtoolsPanelRef } from '@tanstack/angular-query-devtools-experimental'
import type { DevtoolsPanelRef } from '@tanstack/angular-query-experimental/devtools-panel'

@Component({
selector: 'lazy-load-devtools-panel-example',
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class LazyLoadDevtoolsPanelExampleComponent {
if (this.devtools()) return
if (this.isOpen()) {
this.devtools.set(
import('@tanstack/angular-query-devtools-experimental').then(
import('@tanstack/angular-query-experimental/devtools-panel').then(
({ injectDevtoolsPanel }) =>
injectDevtoolsPanel(this.devToolsOptions, {
injector: this.injector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { projectsMockInterceptor } from './api/projects-mock.interceptor'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/optimistic-updates/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { mockInterceptor } from './interceptor/mock-api.interceptor'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/pagination/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { projectsMockInterceptor } from './api/projects-mock.interceptor'
import type { ApplicationConfig } from '@angular/core'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { provideRouter, withComponentInputBinding } from '@angular/router'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'

import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { routes } from './app.routes'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/router/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { provideRouter, withComponentInputBinding } from '@angular/router'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'

import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { routes } from './app.routes'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/rxjs/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import { autocompleteMockInterceptor } from './api/autocomplete-mock.interceptor'
import type { ApplicationConfig } from '@angular/core'

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/simple/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { provideHttpClient, withFetch } from '@angular/common/http'
import {
QueryClient,
provideTanStackQuery,
withDevtools,
} from '@tanstack/angular-query-experimental'
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
import type { ApplicationConfig } from '@angular/core'

export const appConfig: ApplicationConfig = {
Expand Down
3 changes: 3 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
],
"ignoreWorkspaces": ["examples/**", "integrations/**"],
"workspaces": {
"packages/angular-query-experimental": {
"ignore": ["**/production/index.ts"]
},
"packages/query-codemods": {
"entry": ["src/v4/**/*.cjs", "src/v5/**/*.cjs"],
"ignore": ["**/__testfixtures__/**"]
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
},
"pnpm": {
"overrides": {
"@tanstack/angular-query-devtools-experimental": "workspace:*",
"@tanstack/angular-query-experimental": "workspace:*",
"@tanstack/eslint-plugin-query": "workspace:*",
"@tanstack/query-async-storage-persister": "workspace:*",
Expand Down
7 changes: 0 additions & 7 deletions packages/angular-query-devtools-experimental/.attw.json

This file was deleted.

17 changes: 0 additions & 17 deletions packages/angular-query-devtools-experimental/eslint.config.js

This file was deleted.

Loading
Loading