Skip to content

Commit c64a5ea

Browse files
committed
Merge branch 'main' of https://github.com/TanStack/query into refactor/resolveValueOrFunction
2 parents 8955b0d + 2a00fb6 commit c64a5ea

File tree

312 files changed

+4025
-2621
lines changed

Some content is hidden

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

312 files changed

+4025
-2621
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: |
6666
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha || github.sha }}" >> $GITHUB_ENV
6767
- name: Preview Bundle Size
68-
uses: marocchino/sticky-pull-request-comment@9c40848920de7cd32a71773ba792d8b04f03bf7a
68+
uses: marocchino/sticky-pull-request-comment@a071bc9e79df3f13d7cd94d06ab2ef1ec959e9fa
6969
with:
7070
message: |
7171
Sizes for commit ${{ env.COMMIT_SHA }}:

README.md

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,98 @@
11
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=be2d8a11-9712-4c1d-9963-580b2d4fb133" />
22

3-
![TanStack Query Header](https://github.com/TanStack/query/raw/main/media/repo-header.png)
4-
5-
Hooks for fetching, caching and updating asynchronous data in React, Solid, Svelte and Vue
6-
7-
<a href="https://twitter.com/intent/tweet?button_hashtag=TanStack" target="\_parent">
8-
<img alt="#TanStack" src="https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack">
9-
</a><a href="https://discord.com/invite/WrRKjPJ" target="\_parent">
10-
<img alt="" src="https://img.shields.io/badge/Discord-TanStack-%235865F2" />
11-
</a><a href="https://www.npmjs.com/package/@tanstack/query-core" target="\_parent">
12-
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/query-core.svg" />
13-
</a><a href="https://bundlejs.com/?q=%40tanstack%2Freact-query&config=%7B%22esbuild%22%3A%7B%22external%22%3A%5B%22react%22%2C%22react-dom%22%5D%7D%7D&badge=" target="\_parent">
14-
<img alt="" src="https://deno.bundlejs.com/?q=@tanstack/react-query&config={%22esbuild%22:{%22external%22:[%22react%22,%22react-dom%22]}}&badge=detailed" />
15-
</a><a href="#badge">
16-
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
17-
</a><a href="https://github.com/TanStack/query/discussions">
18-
<img alt="Join the discussion on Github" src="https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue" />
19-
</a><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><a href="https://github.com/TanStack/query/" target="\_parent">
20-
<img alt="" src="https://img.shields.io/github/stars/TanStack/query.svg?style=social&label=Star" />
21-
</a><a href="https://twitter.com/tannerlinsley" target="\_parent">
22-
<img alt="" src="https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow" />
23-
</a> <a href="https://gitpod.io/from-referrer/">
24-
<img src="https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod" alt="Gitpod Ready-to-Code"/>
3+
<div align="center">
4+
<img src="./media/header_query.png" alt="TanStack Query" />
5+
</div>
6+
7+
<br />
8+
9+
<div align="center">
10+
<a href="https://www.npmjs.com/package/@tanstack/query-core" target="\_parent">
11+
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/query-core.svg" alt="npm downloads" />
12+
</a>
13+
<a href="https://github.com/TanStack/query/" target="\_parent">
14+
<img alt="" src="https://img.shields.io/github/stars/TanStack/query.svg?style=social&label=Star" alt="GitHub stars" />
15+
</a>
16+
<a href="https://bundlejs.com/?q=%40tanstack%2Freact-query&config=%7B%22esbuild%22%3A%7B%22external%22%3A%5B%22react%22%2C%22react-dom%22%5D%7D%7D&badge=" target="\_parent">
17+
<img alt="" src="https://deno.bundlejs.com/?q=@tanstack/react-query&config={%22esbuild%22:{%22external%22:[%22react%22,%22react-dom%22]}}&badge=detailed" alt="Bundle size" />
2518
</a>
19+
</div>
20+
21+
<div align="center">
22+
<a href="#badge">
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">
24+
</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>
26+
<a href="https://twitter.com/tan_stack"><img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/></a>
27+
</div>
28+
29+
<div align="center">
30+
31+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
32+
33+
</div>
2634

27-
Enjoy this library? Try the entire [TanStack](https://tanstack.com)! [TanStack Table](https://github.com/TanStack/table), [TanStack Router](https://github.com/tanstack/router), [TanStack Virtual](https://github.com/tanstack/virtual), [React Charts](https://github.com/TanStack/react-charts), [React Ranger](https://github.com/TanStack/ranger)
35+
# TanStack Query
2836

29-
## Visit [tanstack.com/query](https://tanstack.com/query) for docs, guides, API and more!
37+
An async state management library built to simplify fetching, caching, synchronizing, and updating server state.
3038

31-
Still on **React Query v2**? No problem! Check out the v2 docs here: https://github.com/TanStack/query/tree/2.x/docs/src/pages/docs.<br />
32-
Still on **React Query v3**? No problem! Check out the v3 docs here: https://tanstack.com/query/v3/docs/.<br />
33-
Still on **React Query v4**? No problem! Check out the v4 docs here: https://tanstack.com/query/v4/docs/.
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
3443

35-
## Quick Features
44+
### <a href="https://tanstack.com/query">Read the docs →</b></a>
3645

37-
- Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
38-
- Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
39-
- Parallel + Dependent Queries
40-
- Mutations + Reactive Query Refetching
41-
- Multi-layer Cache + Automatic Garbage Collection
42-
- Paginated + Cursor-based Queries
43-
- Load-More + Infinite Scroll Queries w/ Scroll Recovery
44-
- Request Cancellation
45-
- [React Suspense](https://react.dev/reference/react/Suspense) + Fetch-As-You-Render Query Prefetching
46-
- Dedicated Devtools
46+
## Get Involved
47+
48+
- We welcome issues and pull requests!
49+
- Participate in [GitHub discussions](https://github.com/TanStack/query/discussions)
50+
- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
51+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
4752

4853
## Partners
4954

50-
<a href="https://www.speakeasy.com/product/react-query?utm_source=tanstack&utm_campaign=tanstack">
51-
<picture>
52-
<source
53-
srcset="https://tanstack.com/assets/speakeasy-dark-BjP-Hd9M.svg"
54-
media="(prefers-color-scheme: dark)"
55-
/>
56-
<source
57-
srcset="https://tanstack.com/assets/speakeasy-light-UpY7QmwQ.svg"
58-
media="(prefers-color-scheme: light)"
59-
/>
60-
<!-- fallback -->
61-
<img
62-
src="https://tanstack.com/assets/speakeasy-light-UpY7QmwQ.svg"
63-
alt="Speakeasy Logo"
64-
/>
65-
</picture>
66-
</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>
6770

68-
## Contributing
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>
6978

70-
View the contributing guidelines [here](/CONTRIBUTING.md)
79+
</div>
7180

72-
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
81+
## Explore the TanStack Ecosystem
82+
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>
7397

7498
<!-- 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/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@
757757
{
758758
"label": "notifyManager",
759759
"to": "reference/notifyManager"
760+
},
761+
{
762+
"label": "timeoutManager",
763+
"to": "reference/timeoutManager"
760764
}
761765
],
762766
"frameworks": [

docs/framework/angular/angular-httpclient-and-other-data-fetching-clients.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Because TanStack Query's fetching mechanisms are agnostically built on Promises,
1111

1212
- Mock responses in unit tests using [provideHttpClientTesting](https://angular.dev/guide/http/testing).
1313
- [Interceptors](https://angular.dev/guide/http/interceptors) can be used for a wide range of functionality including adding authentication headers, performing logging, etc. While some data fetching libraries have their own interceptor system, `HttpClient` interceptors are integrated with Angular's dependency injection system.
14-
- `HttpClient` automatically informs [`PendingTasks`](https://angular.dev/api/core/PendingTasks#), which enables Angular to be aware of pending requests. Unit tests and SSR can use the resulting application _stableness_ information to wait for pending requests to finish. This makes unit testing much easier for [Zoneless](https://angular.dev/guide/experimental/zoneless) applications.
14+
- `HttpClient` automatically informs [`PendingTasks`](https://angular.dev/api/core/PendingTasks#), which enables Angular to be aware of pending requests. Unit tests and SSR can use the resulting application _stableness_ information to wait for pending requests to finish. This makes unit testing much easier for [Zoneless](https://angular.dev/guide/zoneless) applications.
1515
- When using SSR, `HttpClient` will [cache requests](https://angular.dev/guide/ssr#caching-data-when-using-HttpClient) performed on the server. This will prevent unneeded requests on the client. `HttpClient` SSR caching works out of the box. TanStack Query has its own hydration functionality which may be more powerful but requires some setup. Which one fits your needs best depends on your use case.
1616

1717
### Using observables in `queryFn`

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.

0 commit comments

Comments
 (0)