Skip to content

Commit 7179927

Browse files
committed
Merge branch 'main' into feat/mutationfn-context
2 parents 0c5823d + 66df211 commit 7179927

File tree

143 files changed

+1849
-1644
lines changed

Some content is hidden

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

143 files changed

+1849
-1644
lines changed

README.md

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@
44
<img src="./media/header_query.png" alt="TanStack Query" />
55
</div>
66

7-
An async state management library built to simplify fetching, caching, synchronizing, and updating server state.
8-
9-
- Protocol‑agnostic fetching (REST, GraphQL, promises, etc.)
10-
- Caching, refetching, pagination & infinite scroll
11-
- Mutations, dependent queries & background updates
12-
- Prefetching, cancellation & React Suspense support
13-
14-
<a href="https://tanstack.com/query" style="font-weight: bold">Read the Query Docs →</a>
157
<br />
168

17-
<div align="center" style="display: flex; gap: 10px; flex-direction: column; justify-content: center;">
18-
199
<div align="center">
2010
<a href="https://www.npmjs.com/package/@tanstack/query-core" target="\_parent">
2111
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/query-core.svg" alt="npm downloads" />
@@ -30,19 +20,28 @@ An async state management library built to simplify fetching, caching, synchroni
3020

3121
<div align="center">
3222
<a href="#badge">
33-
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
23+
<img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release">
3424
</a>
35-
<a href="https://bestofjs.org/projects/tanstack-query"><img alt="Best of JS" src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=TanStack%2Fquery%26since=daily" /></a>
25+
<a href="https://bestofjs.org/projects/tanstack-query"><img src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=TanStack%2Fquery%26since=daily" alt="Best of JS" /></a>
3626
<a href="https://twitter.com/tan_stack"><img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/></a>
3727
</div>
3828

39-
<div align="center" style="font-size: 2rem; font-weight: bolder;">
29+
<div align="center">
4030

41-
[Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
31+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
4232

4333
</div>
4434

45-
</div>
35+
# TanStack Query
36+
37+
An async state management library built to simplify fetching, caching, synchronizing, and updating server state.
38+
39+
- Protocol‑agnostic fetching (REST, GraphQL, promises, etc.)
40+
- Caching, refetching, pagination & infinite scroll
41+
- Mutations, dependent queries & background updates
42+
- Prefetching, cancellation & React Suspense support
43+
44+
### <a href="https://tanstack.com/query">Read the docs →</b></a>
4645

4746
## Get Involved
4847

@@ -53,41 +52,47 @@ An async state management library built to simplify fetching, caching, synchroni
5352

5453
## Partners
5554

56-
<div style="display: flex; flex-wrap: wrap; gap: 50px; justify-content: center; align-items: center;">
57-
<a href="https://www.speakeasy.com/product/react-query?utm_source=tanstack&utm_campaign=tanstack">
58-
<picture>
59-
<source
60-
srcset="https://tanstack.com/assets/speakeasy-dark-BjP-Hd9M.svg"
61-
media="(prefers-color-scheme: dark)"
62-
/>
63-
<source
64-
srcset="https://tanstack.com/assets/speakeasy-light-UpY7QmwQ.svg"
65-
media="(prefers-color-scheme: light)"
66-
/>
67-
<!-- fallback -->
68-
<img
69-
src="https://tanstack.com/assets/speakeasy-light-UpY7QmwQ.svg"
70-
alt="Speakeasy Logo"
71-
/>
72-
</picture>
73-
</a>
55+
<table align="center">
56+
<tr>
57+
<td>
58+
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
59+
<img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" padding="20px" alt="Code Rabbit"/>
60+
</a>
61+
</td>
62+
<td padding="20">
63+
<a href="https://www.cloudflare.com?utm_source=tanstack">
64+
<img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="70" alt="Cloudflare"/>
65+
</a>
66+
</td>
67+
</tr>
68+
69+
</table>
70+
71+
<div align="center">
72+
<img src="./media/partner_logo.svg" alt="Query & you?" height="65">
73+
<p>
74+
We're looking for TanStack Query Partners to join our mission! Partner with us to push the boundaries of TanStack Query and build amazing things together.
75+
</p>
76+
<a href="mailto:[email protected]?subject=TanStack Query Partnership"><b>LET'S CHAT</b></a>
77+
</div>
78+
7479
</div>
7580

7681
## Explore the TanStack Ecosystem
7782

78-
<div align="center">
79-
<a href="https://github.com/tanstack/config" style="font-weight: bold;">TanStack Config</a> – Tooling for JS/TS packages <br/>
80-
<a href="https://github.com/tanstack/db" style="font-weight: bold;">TanStack DB</a> – Reactive sync client store <br/>
81-
<a href="https://github.com/tanstack/devtools" style="font-weight: bold;">TanStack DevTools</a> – Unified devtools panel <br/>
82-
<a href="https://github.com/tanstack/form" style="font-weight: bold;">TanStack Form</a> – Type‑safe form state <br/>
83-
<a href="https://github.com/tanstack/pacer" style="font-weight: bold;">TanStack Pacer</a> – Debouncing, throttling, batching <br/>
84-
<a href="https://github.com/tanstack/ranger" style="font-weight: bold;">TanStack Ranger</a> – Range & slider primitives <br/>
85-
<a href="https://github.com/tanstack/router" style="font-weight: bold;">TanStack Router</a> – Type‑safe routing, caching & URL state<br/>
86-
<a href="https://github.com/tanstack/router" style="font-weight: bold;">TanStack Start</a> – Full‑stack SSR & streaming<br/>
87-
<a href="https://github.com/tanstack/store" style="font-weight: bold;">TanStack Store</a> – Reactive data store <br/>
88-
<a href="https://github.com/tanstack/table" style="font-weight: bold;">TanStack Table</a> – Headless datagrids <br/>
89-
<a href="https://github.com/tanstack/virtual" style="font-weight: bold;">TanStack Virtual</a> – Virtualized rendering <br/>
90-
… and more at <a href="https://tanstack.com" style="font-weight: bold;">TanStack.com »</a>
91-
</div>
83+
- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
84+
- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
85+
- <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
86+
- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
87+
- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching <br/>
88+
- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
89+
- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
90+
- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
91+
- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
92+
- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
93+
- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids
94+
- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
95+
96+
… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
9297

9398
<!-- Use the force, Luke -->

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/mutations.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class TodosComponent {
4747

4848
```angular-ts
4949
@Component({
50-
standalone: true,
5150
selector: 'todo-item',
5251
imports: [ReactiveFormsModule],
5352
template: `

docs/framework/angular/guides/queries.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ result = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList }))
3737
```angular-ts
3838
@Component({
3939
selector: 'todos',
40-
standalone: true,
4140
template: `
4241
@if (todos.isPending()) {
4342
<span>Loading...</span>
@@ -70,7 +69,6 @@ If booleans aren't your thing, you can always use the `status` state as well:
7069
```angular-ts
7170
@Component({
7271
selector: 'todos',
73-
standalone: true,
7472
template: `
7573
@switch (todos.status()) {
7674
@case ('pending') {

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

Lines changed: 1 addition & 2 deletions
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(() => ({
@@ -83,7 +83,6 @@ You might want to cancel a query manually. For example, if the request takes a l
8383

8484
```angular-ts
8585
@Component({
86-
standalone: true,
8786
template: `<button (click)="onCancel()">Cancel</button>`,
8887
})
8988
export class TodosComponent {

docs/framework/angular/overview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import { lastValueFrom } from 'rxjs'
7070
@Component({
7171
changeDetection: ChangeDetectionStrategy.OnPush,
7272
selector: 'simple-example',
73-
standalone: true,
7473
template: `
7574
@if (query.isPending()) {
7675
Loading...

docs/framework/angular/quick-start.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
} from '@tanstack/angular-query-experimental'
5656
5757
@Component({
58-
standalone: true,
5958
template: `
6059
<div>
6160
<button (click)="onAddTodo()">Add Todo</button>

0 commit comments

Comments
 (0)