Skip to content

Commit 95d9f86

Browse files
authored
Merge branch 'main' into fix/hydration-boundary-double-fetch
2 parents c37ad5e + 8a59b2d commit 95d9f86

166 files changed

Lines changed: 6883 additions & 807 deletions

File tree

Some content is hidden

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

docs/config.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@
183183
"label": "Quick Start",
184184
"to": "framework/preact/quick-start"
185185
},
186+
{
187+
"label": "Devtools",
188+
"to": "framework/preact/devtools"
189+
},
186190
{
187191
"label": "TypeScript",
188192
"to": "framework/preact/typescript"
@@ -1140,6 +1144,10 @@
11401144
{
11411145
"label": "Functions / infiniteQueryOptions",
11421146
"to": "framework/svelte/reference/functions/infiniteQueryOptions"
1147+
},
1148+
{
1149+
"label": "Functions / mutationOptions",
1150+
"to": "framework/svelte/reference/functions/mutationOptions"
11431151
}
11441152
]
11451153
},
@@ -1419,6 +1427,10 @@
14191427
{
14201428
"label": "Astro",
14211429
"to": "framework/solid/examples/astro"
1430+
},
1431+
{
1432+
"label": "Offline Queries and Mutations",
1433+
"to": "framework/solid/examples/offline"
14221434
}
14231435
]
14241436
},
@@ -1585,6 +1597,31 @@
15851597
"to": "framework/vue/plugins/createPersister"
15861598
}
15871599
]
1600+
},
1601+
{
1602+
"label": "preact",
1603+
"children": [
1604+
{
1605+
"label": "persistQueryClient",
1606+
"to": "framework/preact/plugins/persistQueryClient"
1607+
},
1608+
{
1609+
"label": "createSyncStoragePersister",
1610+
"to": "framework/preact/plugins/createSyncStoragePersister"
1611+
},
1612+
{
1613+
"label": "createAsyncStoragePersister",
1614+
"to": "framework/preact/plugins/createAsyncStoragePersister"
1615+
},
1616+
{
1617+
"label": "broadcastQueryClient (Experimental)",
1618+
"to": "framework/preact/plugins/broadcastQueryClient"
1619+
},
1620+
{
1621+
"label": "createPersister (Experimental)",
1622+
"to": "framework/preact/plugins/createPersister"
1623+
}
1624+
]
15881625
}
15891626
]
15901627
}

docs/framework/angular/guides/caching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Let's assume we are using the default `gcTime` of **5 minutes** and the default
1919
- A new instance of `injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodos }))` initializes.
2020
- Since no other queries have been made with the `['todos']` query key, this query will show a hard loading state and make a network request to fetch the data.
2121
- When the network request has completed, the returned data will be cached under the `['todos']` key.
22-
- The date will be marked as stale after the configured `staleTime` (defaults to `0`, or immediately).
22+
- The data will be marked as stale after the configured `staleTime` (defaults to `0`, or immediately).
2323
- A second instance of `injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodos }))` initializes elsewhere.
2424
- Since the cache already has data for the `['todos']` key from the first query, that data is immediately returned from the cache.
2525
- The new instance triggers a new network request using its query function.

docs/framework/angular/guides/paginated-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const result = injectQuery(() => ({
7070
})
7171
export class PaginationExampleComponent {
7272
page = signal(0)
73-
queryClient = inject(QueryClient)
73+
#queryClient = inject(QueryClient)
7474
7575
query = injectQuery(() => ({
7676
queryKey: ['projects', this.page()],

docs/framework/preact/devtools.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
id: devtools
3+
title: Devtools
4+
---
5+
6+
Wave your hands in the air and shout hooray because Preact Query comes with dedicated devtools! 🥳
7+
8+
When you begin your Preact Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of Preact Query and will likely save you hours of debugging if you find yourself in a pinch!
9+
10+
> 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:
11+
>
12+
> - <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)
13+
> - <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/)
14+
> - <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)
15+
16+
## Install and Import the Devtools
17+
18+
The devtools are a separate package that you need to install:
19+
20+
```bash
21+
npm i @tanstack/preact-query-devtools
22+
```
23+
24+
or
25+
26+
```bash
27+
pnpm add @tanstack/preact-query-devtools
28+
```
29+
30+
or
31+
32+
```bash
33+
yarn add @tanstack/preact-query-devtools
34+
```
35+
36+
or
37+
38+
```bash
39+
bun add @tanstack/preact-query-devtools
40+
```
41+
42+
You can import the devtools like this:
43+
44+
```tsx
45+
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
46+
```
47+
48+
By default, Preact Query Devtools are only included in bundles when `process.env.NODE_ENV === 'development'`, so you don't need to worry about excluding them during a production build.
49+
50+
## Floating Mode
51+
52+
Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
53+
54+
Place the following code as high in your Preact app as you can. The closer it is to the root of the page, the better it will work!
55+
56+
```tsx
57+
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
58+
59+
function App() {
60+
return (
61+
<QueryClientProvider client={queryClient}>
62+
{/* The rest of your application */}
63+
<PreactQueryDevtools initialIsOpen={false} />
64+
</QueryClientProvider>
65+
)
66+
}
67+
```
68+
69+
### Options
70+
71+
- `initialIsOpen: boolean`
72+
- Set this `true` if you want the dev tools to default to being open
73+
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
74+
- Defaults to `bottom-right`
75+
- The position of the Preact Query logo to open and close the devtools panel
76+
- `position?: "top" | "bottom" | "left" | "right"`
77+
- Defaults to `bottom`
78+
- The position of the Preact Query devtools panel
79+
- `client?: QueryClient`,
80+
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
81+
- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
82+
- 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.
83+
- `styleNonce?: string`
84+
- 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.
85+
- `shadowDOMTarget?: ShadowRoot`
86+
- Default behavior will apply the devtool's styles to the head tag within the DOM.
87+
- 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.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: createAsyncStoragePersister
3+
title: createAsyncStoragePersister
4+
ref: docs/framework/react/plugins/createAsyncStoragePersister.md
5+
replace: { 'react-query': 'preact-query' }
6+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: createPersister
3+
title: experimental_createPersister
4+
ref: docs/framework/react/plugins/createPersister.md
5+
replace: { 'react-query': 'preact-query' }
6+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: createSyncStoragePersister
3+
title: createSyncStoragePersister
4+
ref: docs/framework/react/plugins/createSyncStoragePersister.md
5+
replace: { 'react-query': 'preact-query' }
6+
---

docs/framework/react/guides/caching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Let's assume we are using the default `gcTime` of **5 minutes** and the default
1919
- A new instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts.
2020
- Since no other queries have been made with the `['todos']` query key, this query will show a hard loading state and make a network request to fetch the data.
2121
- When the network request has completed, the returned data will be cached under the `['todos']` key.
22-
- The hook will mark the data as stale after the configured `staleTime` (defaults to `0`, or immediately).
22+
- The data will be marked as stale after the configured `staleTime` (defaults to `0`, or immediately).
2323
- A second instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts elsewhere.
2424
- Since the cache already has data for the `['todos']` key from the first query, that data is immediately returned from the cache.
2525
- The new instance triggers a new network request using its query function.

docs/framework/react/guides/important-defaults.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ Out of the box, TanStack Query is configured with **aggressive but sane** defaul
3232

3333
> To change this, you can alter the default `retry` and `retryDelay` options for queries to something other than `3` and the default exponential backoff function.
3434
35+
[//]: # 'StructuralSharing'
36+
3537
- Query results by default are **structurally shared to detect if data has actually changed** and if not, **the data reference remains unchanged** to better help with value stabilization with regards to useMemo and useCallback. If this concept sounds foreign, then don't worry about it! 99.9% of the time you will not need to disable this and it makes your app more performant at zero cost to you.
3638

37-
> Structural sharing only works with JSON-compatible values, any other value types will always be considered as changed. If you are seeing performance issues because of large responses for example, you can disable this feature with the `config.structuralSharing` flag. If you are dealing with non-JSON compatible values in your query responses and still want to detect if data has changed or not, you can provide your own custom function as `config.structuralSharing` to compute a value from the old and new responses, retaining references as required.
39+
[//]: # 'StructuralSharing'
40+
41+
> Structural sharing only works with JSON-compatible values, any other value types will always be considered as changed. If you are seeing performance issues because of large responses for example, you can disable this feature with the `config.structuralSharing` flag. If you are dealing with non-JSON compatible values in your query responses and still want to detect if data has changed or not, you can provide your own custom function as `config.structuralSharing` to compute a value from the old and new responses, retaining references as required.
3842
3943
[//]: # 'Materials'
4044

docs/framework/react/guides/mutations.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,14 @@ queryClient.resumePausedMutations()
340340
```
341341

342342
[//]: # 'Example10'
343+
[//]: # 'PersistOfflineIntro'
343344

344345
### Persisting Offline mutations
345346

346347
If you persist offline mutations with the [persistQueryClient plugin](../plugins/persistQueryClient.md), mutations cannot be resumed when the page is reloaded unless you provide a default mutation function.
347348

349+
[//]: # 'PersistOfflineIntro'
350+
348351
This is a technical limitation. When persisting to an external storage, only the state of mutations is persisted, as functions cannot be serialized. After hydration, the component that triggers the mutation might not be mounted, so calling `resumePausedMutations` might yield an error: `No mutationFn found`.
349352

350353
[//]: # 'Example11'
@@ -385,9 +388,12 @@ export default function App() {
385388
```
386389

387390
[//]: # 'Example11'
391+
[//]: # 'OfflineExampleLink'
388392

389393
We also have an extensive [offline example](../examples/offline) that covers both queries and mutations.
390394

395+
[//]: # 'OfflineExampleLink'
396+
391397
## Mutation Scopes
392398

393399
Per default, all mutations run in parallel - even if you invoke `.mutate()` of the same mutation multiple times. Mutations can be given a `scope` with an `id` to avoid that. All mutations with the same `scope.id` will run in serial, which means when they are triggered, they will start in `isPaused: true` state if there is already a mutation for that scope in progress. They will be put into a queue and will automatically resume once their time in the queue has come.

0 commit comments

Comments
 (0)