Skip to content

Commit e75a5f9

Browse files
feat(angular-query): move devtools to conditional sub-paths (#9270)
* feat(angular-query-devtools): move devtools to conditional sub-paths, improves tree shaking and dependency injection * Fix compatibility with moduleResolution node * ci: apply automated fixes * fix preview release for angular-query * Fix angular-query preview release * Revert some changes made obsolete by better Vite based alternative * Update export paths * Fix production exports and publishconfig * knip config * remove postpack * Generate API reference docs * type declarations in correct directory * Update documentation * knip config * Optional core devtools dependency * ci: apply automated fixes * regenerate api reference docs * ci: apply automated fixes * ci: apply automated fixes (attempt 2/3) * regenerate api reference docs * formatting * apply coderabbit suggestions * Improve unit tests * docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 2b0d97a commit e75a5f9

File tree

118 files changed

+1741
-1567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1741
-1567
lines changed

codecov.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ comment:
1919

2020
component_management:
2121
individual_components:
22-
- component_id: angular-query-devtools-experimental
23-
name: '@tanstack/angular-query-devtools-experimental'
24-
paths:
25-
- packages/angular-query-devtools-experimental/**
2622
- component_id: angular-query-experimental
2723
name: '@tanstack/angular-query-experimental'
2824
paths:

docs/framework/angular/devtools.md

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,38 @@ title: Devtools
1313

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

16-
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.
16+
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.
1717

1818
```ts
1919
import {
2020
QueryClient,
2121
provideTanStackQuery,
22-
withDevtools,
2322
} from '@tanstack/angular-query-experimental'
2423

24+
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
25+
2526
export const appConfig: ApplicationConfig = {
2627
providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
2728
}
2829
```
2930

30-
## Configuring if devtools are loaded
31+
## Devtools in production
3132

32-
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.
33+
Devtools are automatically excluded from production builds. However, it might be desirable to lazy load the devtools in production.
3334

34-
When not setting the option or setting it to 'auto', the devtools will be loaded when Angular is in development mode.
35+
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.
3536

3637
```ts
38+
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
39+
```
40+
41+
To control when devtools are loaded, you can use the `loadDevtools` option.
42+
43+
When 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
46+
import { withDevtools } from '@tanstack/angular-query-experimental/devtools'
47+
3748
provideTanStackQuery(new QueryClient(), withDevtools())
3849

3950
// which is equivalent to
@@ -45,10 +56,16 @@ provideTanStackQuery(
4556

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

59+
This 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+
4861
```ts
62+
import { environment } from './environments/environment'
63+
// Make sure to use the production sub-path to load devtools in production builds
64+
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
65+
4966
provideTanStackQuery(
5067
new QueryClient(),
51-
withDevtools(() => ({ loadDevtools: true })),
68+
withDevtools(() => ({ loadDevtools: environment.loadDevtools })),
5269
)
5370
```
5471

@@ -61,44 +78,66 @@ provideTanStackQuery(
6178
)
6279
```
6380

64-
The `withDevtools` options are returned from a callback function to support reactivity through signals. In the following example
65-
a signal is created from a RxJS observable that listens for a keyboard shortcut. When the event is triggered, the devtools are lazily loaded.
66-
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.
81+
## Derive options through reactivity
82+
83+
Options are passed to `withDevtools` from a callback function to support reactivity through signals. In the following example
84+
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.
85+
86+
The example below always loads devtools in development mode and loads on-demand in production mode when a keyboard shortcut is pressed.
6787

6888
```ts
89+
import { Injectable, isDevMode } from '@angular/core'
90+
import { fromEvent, map, scan } from 'rxjs'
91+
import { toSignal } from '@angular/core/rxjs-interop'
92+
6993
@Injectable({ providedIn: 'root' })
70-
class DevtoolsOptionsManager {
94+
export class DevtoolsOptionsManager {
7195
loadDevtools = toSignal(
7296
fromEvent<KeyboardEvent>(document, 'keydown').pipe(
7397
map(
7498
(event): boolean =>
7599
event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
76100
),
77-
scan((acc, curr) => acc || curr, false),
101+
scan((acc, curr) => acc || curr, isDevMode()),
78102
),
79103
{
80-
initialValue: false,
104+
initialValue: isDevMode(),
81105
},
82106
)
83107
}
108+
```
109+
110+
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.
111+
112+
This 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
117+
import { withDevtools } from '@tanstack/angular-query-experimental/devtools/production'
84118

85119
export const appConfig: ApplicationConfig = {
86120
providers: [
87121
provideHttpClient(),
88122
provideTanStackQuery(
89123
new QueryClient(),
90-
withDevtools(() => ({
91-
initialIsOpen: true,
92-
loadDevtools: inject(DevtoolsOptionsManager).loadDevtools(),
93-
})),
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+
),
94133
),
95134
],
96135
}
97136
```
98137

99-
### Options
138+
### Options returned from the callback
100139

101-
Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
140+
Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
102141

103142
- `loadDevtools?: 'auto' | boolean`
104143
- Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
@@ -121,3 +160,5 @@ Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `init
121160
- `shadowDOMTarget?: ShadowRoot`
122161
- Default behavior will apply the devtool's styles to the head tag within the DOM.
123162
- 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+
- Set this to true to hide disabled queries from the devtools panel.

docs/framework/angular/guides/query-cancellation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ query = injectQuery(() => ({
6060

6161
[//]: # 'Example3'
6262

63-
```tsx
63+
```ts
6464
import axios from 'axios'
6565

6666
const query = injectQuery(() => ({

docs/framework/angular/reference/functions/infinitequeryoptions.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: infiniteQueryOptions
33
title: infiniteQueryOptions
44
---
55

6+
<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7+
68
# Function: infiniteQueryOptions()
79

810
Allows to share and re-use infinite query options in a type-safe way.
@@ -24,16 +26,19 @@ function infiniteQueryOptions<
2426
TPageParam,
2527
>(
2628
options,
27-
): DefinedInitialDataInfiniteOptions<
29+
): CreateInfiniteQueryOptions<
2830
TQueryFnData,
2931
TError,
3032
TData,
3133
TQueryKey,
3234
TPageParam
3335
> &
36+
object &
3437
object
3538
```
3639

40+
Defined in: [infinite-query-options.ts:88](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L88)
41+
3742
Allows to share and re-use infinite query options in a type-safe way.
3843

3944
The `queryKey` will be tagged with the type from `queryFn`.
@@ -60,7 +65,7 @@ The infinite query options to tag with the type from `queryFn`.
6065

6166
### Returns
6267

63-
[`DefinedInitialDataInfiniteOptions`](../../type-aliases/definedinitialdatainfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
68+
[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` & `object`
6469

6570
The tagged infinite query options.
6671

@@ -70,10 +75,6 @@ The tagged infinite query options.
7075

7176
The infinite query options to tag with the type from `queryFn`.
7277

73-
### Defined in
74-
75-
[infinite-query-options.ts:94](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L94)
76-
7778
## Call Signature
7879

7980
```ts
@@ -85,16 +86,22 @@ function infiniteQueryOptions<
8586
TPageParam,
8687
>(
8788
options,
88-
): UnusedSkipTokenInfiniteOptions<
89-
TQueryFnData,
90-
TError,
91-
TData,
92-
TQueryKey,
93-
TPageParam
89+
): OmitKeyof<
90+
CreateInfiniteQueryOptions<
91+
TQueryFnData,
92+
TError,
93+
TData,
94+
TQueryKey,
95+
TPageParam
96+
>,
97+
'queryFn'
9498
> &
99+
object &
95100
object
96101
```
97102

103+
Defined in: [infinite-query-options.ts:119](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L119)
104+
98105
Allows to share and re-use infinite query options in a type-safe way.
99106

100107
The `queryKey` will be tagged with the type from `queryFn`.
@@ -121,7 +128,7 @@ The infinite query options to tag with the type from `queryFn`.
121128

122129
### Returns
123130

124-
[`UnusedSkipTokenInfiniteOptions`](../../type-aliases/unusedskiptokeninfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
131+
`OmitKeyof`\<[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>, `"queryFn"`\> & `object` & `object`
125132

126133
The tagged infinite query options.
127134

@@ -131,10 +138,6 @@ The tagged infinite query options.
131138

132139
The infinite query options to tag with the type from `queryFn`.
133140

134-
### Defined in
135-
136-
[infinite-query-options.ts:126](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L126)
137-
138141
## Call Signature
139142

140143
```ts
@@ -146,16 +149,19 @@ function infiniteQueryOptions<
146149
TPageParam,
147150
>(
148151
options,
149-
): UndefinedInitialDataInfiniteOptions<
152+
): CreateInfiniteQueryOptions<
150153
TQueryFnData,
151154
TError,
152155
TData,
153156
TQueryKey,
154157
TPageParam
155158
> &
159+
object &
156160
object
157161
```
158162

163+
Defined in: [infinite-query-options.ts:150](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L150)
164+
159165
Allows to share and re-use infinite query options in a type-safe way.
160166

161167
The `queryKey` will be tagged with the type from `queryFn`.
@@ -182,7 +188,7 @@ The infinite query options to tag with the type from `queryFn`.
182188

183189
### Returns
184190

185-
[`UndefinedInitialDataInfiniteOptions`](../../type-aliases/undefinedinitialdatainfiniteoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
191+
[`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object` & `object`
186192

187193
The tagged infinite query options.
188194

@@ -191,7 +197,3 @@ The tagged infinite query options.
191197
### Param
192198

193199
The infinite query options to tag with the type from `queryFn`.
194-
195-
### Defined in
196-
197-
[infinite-query-options.ts:158](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L158)

docs/framework/angular/reference/functions/injectinfinitequery.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: injectInfiniteQuery
33
title: injectInfiniteQuery
44
---
55

6+
<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7+
68
# Function: injectInfiniteQuery()
79

810
Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
@@ -31,6 +33,8 @@ function injectInfiniteQuery<
3133
): DefinedCreateInfiniteQueryResult<TData, TError>
3234
```
3335

36+
Defined in: [inject-infinite-query.ts:41](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L41)
37+
3438
Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
3539
Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
3640

@@ -76,10 +80,6 @@ A function that returns infinite query options.
7680

7781
Additional configuration.
7882

79-
### Defined in
80-
81-
[inject-infinite-query.ts:42](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L42)
82-
8383
## Call Signature
8484

8585
```ts
@@ -92,6 +92,8 @@ function injectInfiniteQuery<
9292
>(injectInfiniteQueryFn, options?): CreateInfiniteQueryResult<TData, TError>
9393
```
9494

95+
Defined in: [inject-infinite-query.ts:65](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L65)
96+
9597
Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
9698
Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
9799

@@ -137,10 +139,6 @@ A function that returns infinite query options.
137139

138140
Additional configuration.
139141

140-
### Defined in
141-
142-
[inject-infinite-query.ts:67](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L67)
143-
144142
## Call Signature
145143

146144
```ts
@@ -153,6 +151,8 @@ function injectInfiniteQuery<
153151
>(injectInfiniteQueryFn, options?): CreateInfiniteQueryResult<TData, TError>
154152
```
155153

154+
Defined in: [inject-infinite-query.ts:89](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L89)
155+
156156
Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
157157
Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
158158

@@ -172,7 +172,7 @@ Infinite queries can additively "load more" data onto an existing set of data or
172172

173173
#### injectInfiniteQueryFn
174174

175-
() => [`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`, `TPageParam`\>
175+
() => [`CreateInfiniteQueryOptions`](../../interfaces/createinfinitequeryoptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
176176

177177
A function that returns infinite query options.
178178

@@ -197,7 +197,3 @@ A function that returns infinite query options.
197197
### Param
198198

199199
Additional configuration.
200-
201-
### Defined in
202-
203-
[inject-infinite-query.ts:92](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L92)

0 commit comments

Comments
 (0)