Skip to content

Commit d5cd918

Browse files
committed
Merge branch 'beta' of https://github.com/TanStack/query into feature/react-dom-dep
2 parents 6a29134 + c6716ea commit d5cd918

File tree

21 files changed

+158
-59
lines changed

21 files changed

+158
-59
lines changed

docs/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@
302302
"to": "plugins/persistQueryClient"
303303
},
304304
{
305-
"label": "createWebStoragePersister",
306-
"to": "plugins/createWebStoragePersister"
305+
"label": "createSyncStoragePersister",
306+
"to": "plugins/createSyncStoragePersister"
307307
},
308308
{
309309
"label": "createAsyncStoragePersister",

docs/devtools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The devtools are a separate package that you need to install:
1515

1616
```bash
1717
$ npm i @tanstack/react-query-devtools
18+
# or
19+
$ yarn add @tanstack/react-query-devtools
1820
```
1921

2022
You can import the devtools like this:

docs/guides/migrating-to-react-query-4.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: Migrating to React Query 4
55

66
## Breaking Changes
77

8+
v4 is a major version, so there are some breaking changes to be aware of:
9+
810
### react-query is now @tanstack/react-query
911

1012
```diff
@@ -15,6 +17,32 @@ title: Migrating to React Query 4
1517
+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
1618
```
1719

20+
#### Codemod
21+
22+
To make this migration easier, v4 comes with a codemod.
23+
24+
> The codemod is a best efforts attempt to help you migrate the breaking change. Please review the generated code thoroughly! Also, there are edge cases that cannot be found by the code mod, so please keep an eye on the log output.
25+
26+
You can easily apply it by using one (or both) of the following commands:
27+
28+
If you want to run it against `.js` or `.jsx` files, please use the command below:
29+
30+
```
31+
npx jscodeshift --extensions=js,jsx --transform=./node_modules/@tanstack/react-query/codemods/v4/replace-import-specifier.js ./path/to/src/
32+
```
33+
34+
If you want to run it against `.ts` or `.tsx` files, please use the command below:
35+
36+
```
37+
npx jscodeshift --extensions=ts,tsx --parser=tsx --transform=./node_modules/@tanstack/react-query/codemods/v4/replace-import-specifier.js ./path/to/src/
38+
```
39+
40+
Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
41+
42+
**Note:** Applying the codemod might break your code formatting, so please don't forget to run `prettier` and/or `eslint` after you've applied the codemod!
43+
44+
**Note:** The codemod will _only_ change the imports - you still have to install the separate devtools package manually.
45+
1846
### Query Keys (and Mutation Keys) need to be an Array
1947

2048
In v3, Query and Mutation Keys could be a String or an Array. Internally, React Query has always worked with Array Keys only, and we've sometimes exposed this to consumers. For example, in the `queryFn`, you would always get the key as an Array to make working with [Default Query Functions](./default-query-function) easier.
@@ -48,7 +76,7 @@ If you want to run it against `.ts` or `.tsx` files, please use the command belo
4876
npx jscodeshift --extensions=ts,tsx --parser=tsx --transform=./node_modules/@tanstack/react-query/codemods/v4/key-transformation.js ./path/to/src/
4977
```
5078

51-
Please note in the case of `TypeScript` you need to use `tsx` as the parser otherwise, the codemod won't be applied properly!
79+
Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
5280

5381
**Note:** Applying the codemod might break your code formatting, so please don't forget to run `prettier` and/or `eslint` after you've applied the codemod!
5482

@@ -211,7 +239,7 @@ React.useEffect(() => mySideEffectHere(data), [data])
211239

212240
### `persistQueryClient` and the corresponding persister plugins are no longer experimental and have been renamed
213241

214-
The plugins `createWebStoragePersistor` and `createAsyncStoragePersistor` have been renamed to [`createWebStoragePersister`](/plugins/createWebStoragePersister) and [`createAsyncStoragePersister`](/plugins/createAsyncStoragePersister) respectively. The interface `Persistor` in `persistQueryClient` has also been renamed to `Persister`. Checkout [this stackexchange](https://english.stackexchange.com/questions/206893/persister-or-persistor) for the motivation of this change.
242+
The plugins `createWebStoragePersistor` and `createAsyncStoragePersistor` have been renamed to [`createSyncStoragePersister`](/plugins/createSyncStoragePersister) and [`createAsyncStoragePersister`](/plugins/createAsyncStoragePersister) respectively. The interface `Persistor` in `persistQueryClient` has also been renamed to `Persister`. Checkout [this stackexchange](https://english.stackexchange.com/questions/206893/persister-or-persistor) for the motivation of this change.
215243

216244
Since these plugins are no longer experimental, their import paths have also been updated:
217245

@@ -221,7 +249,7 @@ Since these plugins are no longer experimental, their import paths have also bee
221249
- import { createAsyncStoragePersistor } from 'react-query/createAsyncStoragePersistor-experimental'
222250

223251
+ import { persistQueryClient } from '@tanstack/react-query-persist-client'
224-
+ import { createWebStoragePersister } from '@tanstack/query-sync-storage-persister'
252+
+ import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
225253
+ import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
226254
```
227255

@@ -335,6 +363,12 @@ If you were importing anything from `'react-query/react'` directly in your proje
335363

336364
## New Features 🚀
337365

366+
v4 comes with an awesome set of new features:
367+
368+
### Support for React 18
369+
370+
React 18 was released earlier this year, and v4 now has first class support for it and the new concurrent features it brings.
371+
338372
### Proper offline support
339373

340374
In v3, React Query has always fired off queries and mutations, but then taken the assumption that if you want to retry it, you need to be connected to the internet. This has led to several confusing situations:

docs/guides/mutations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ useMutation(addTodo, {
151151
})
152152
```
153153

154-
You might find that you want to **trigger additional callbacks** than the ones defined on `useMutation` when calling `mutate`. This can be used to trigger component-specific side effects. To do that, you can provide any of the same callback options to the `mutate` function after your mutation variable. Supported overrides include: `onSuccess`, `onError` and `onSettled`. Please keep in mind that those additional callbacks won't run if your component unmounts _before_ the mutation finishes.
154+
You might find that you want to **trigger additional callbacks** beyond the ones defined on `useMutation` when calling `mutate`. This can be used to trigger component-specific side effects. To do that, you can provide any of the same callback options to the `mutate` function after your mutation variable. Supported overrides include: `onSuccess`, `onError` and `onSettled`. Please keep in mind that those additional callbacks won't run if your component unmounts _before_ the mutation finishes.
155155

156156
```js
157157
useMutation(addTodo, {
@@ -182,7 +182,7 @@ mutate(todo, {
182182
### Consecutive mutations
183183
There is a slight difference in handling `onSuccess`, `onError` and `onSettled` callbacks when it comes to consecutive mutations. When passed to the `mutate` function, they will be fired up only _once_ and only if the component is still mounted. This is due to the fact that mutation observer is removed and resubscribed every time when the `mutate` function is called. On the contrary, `useMutation` handlers execute for each `mutate` call.
184184

185-
> Be aware that most likely, `mutationFn` passed to `useMutation` is ansynchronous. In that case, the order in which mutations are fulfilled may differ from the order of `mutate` function calls.
185+
> Be aware that most likely, `mutationFn` passed to `useMutation` is asynchronous. In that case, the order in which mutations are fulfilled may differ from the order of `mutate` function calls.
186186
187187
```js
188188
useMutation(addTodo, {
@@ -286,7 +286,7 @@ If you persist offline mutations with the [persistQueryClient plugin](../plugins
286286
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 triggeres the mutation might not be mounted, so calling `resumePausedMutations` might yield an error: `No mutationFn found`.
287287

288288
```js
289-
const persister = createWebStoragePersister({
289+
const persister = createSyncStoragePersister({
290290
storage: window.localStorage,
291291
})
292292
const queryClient = new QueryClient({

docs/guides/ssr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ As demonstrated, it's fine to prefetch some queries and let others fetch on the
111111

112112
There's a catch if you're using [Next.js' rewrites feature](https://nextjs.org/docs/api-reference/next.config.js/rewrites) together with [Automatic Static Optimization](https://nextjs.org/docs/advanced-features/automatic-static-optimization) or `getStaticProps`: It will cause a second hydration by React Query. That's because [Next.js needs to ensure that they parse the rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewrite-parameters) on the client and collect any params after hydration so that they can be provided in `router.query`.
113113

114-
The result is missing referential equality for all the hydration data, which for example triggers whereever your data is used as props of components or in the dependency array of `useEffect`s/`useMemo`s.
114+
The result is missing referential equality for all the hydration data, which for example triggers wherever your data is used as props of components or in the dependency array of `useEffect`s/`useMemo`s.
115115

116116
## Using Other Frameworks or Custom SSR Frameworks
117117

docs/installation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ or a good ol' `<script>` via
1111

1212
```bash
1313
$ npm i @tanstack/react-query
14+
# or
15+
$ yarn add @tanstack/react-query
1416
```
1517

1618
React Query is compatible with React v16.8+ and works with ReactDOM and React Native.
1719

18-
> Wanna give it a spin before you download? Try out the [simple](/docs/examples/simple) or [basic](/docs/examples/basic) examples!
20+
> Wanna give it a spin before you download? Try out the [simple](/query/v4/docs/examples/react/simple) or [basic](/query/v4/docs/examples/react/basic) examples!
1921
2022
### CDN
2123

docs/plugins/createAsyncStoragePersister.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ persistQueryClient({
3939

4040
## Retries
4141

42-
Retries work the same as for a [WebStoragePersister](./createWebStoragePersister), except that they can also be asynchronous. You can also use all the predefined retry handlers.
42+
Retries work the same as for a [SyncStoragePersister](./createSyncStoragePersister), except that they can also be asynchronous. You can also use all the predefined retry handlers.
4343

4444
## API
4545

docs/plugins/createWebStoragePersister.md renamed to docs/plugins/createSyncStoragePersister.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
id: createWebStoragePersister
3-
title: createWebStoragePersister
2+
id: createSyncStoragePersister
3+
title: createSyncStoragePersister
44
---
55

66
## Installation
77

8-
This utility comes packaged with `react-query` and is available under the `react-query/createWebStoragePersister` import.
8+
This utility comes as a separate package and is available under the `'@tanstack/query-sync-storage-persister'` import.
99

1010
## Usage
1111

12-
- Import the `createWebStoragePersister` function
13-
- Create a new webStoragePersister
12+
- Import the `createSyncStoragePersister` function
13+
- Create a new syncStoragePersister
1414
- Pass it to the [`persistQueryClient`](./persistQueryClient) function
1515

1616
```ts
17-
import { persistQueryClient } from 'react-query/persistQueryClient'
18-
import { createWebStoragePersister } from 'react-query/createWebStoragePersister'
17+
import { persistQueryClient } from '@tanstack/react-query-persist-client'
18+
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
1919

2020
const queryClient = new QueryClient({
2121
defaultOptions: {
@@ -25,8 +25,8 @@ const queryClient = new QueryClient({
2525
},
2626
})
2727

28-
const localStoragePersister = createWebStoragePersister({ storage: window.localStorage })
29-
// const sessionStoragePersister = createWebStoragePersister({ storage: window.sessionStorage })
28+
const localStoragePersister = createSyncStoragePersister({ storage: window.localStorage })
29+
// const sessionStoragePersister = createSyncStoragePersister({ storage: window.sessionStorage })
3030

3131
persistQueryClient({
3232
queryClient,
@@ -56,26 +56,26 @@ Per default, no retry will occur. You can use one of the predefined strategies t
5656
- will return a new `PersistedClient` with the oldest query removed.
5757
5858
```js
59-
const localStoragePersister = createWebStoragePersister({
59+
const localStoragePersister = createSyncStoragePersister({
6060
storage: window.localStorage,
6161
retry: removeOldestQuery
6262
})
6363
```
6464

6565
## API
6666

67-
### `createWebStoragePersister`
67+
### `createSyncStoragePersister`
6868

69-
Call this function to create a webStoragePersister that you can use later with `persistQueryClient`.
69+
Call this function to create a syncStoragePersister that you can use later with `persistQueryClient`.
7070

7171
```js
72-
createWebStoragePersister(options: CreateWebStoragePersisterOptions)
72+
createSyncStoragePersister(options: CreateSyncStoragePersisterOptions)
7373
```
7474

7575
### `Options`
7676

7777
```ts
78-
interface CreateWebStoragePersisterOptions {
78+
interface CreateSyncStoragePersisterOptions {
7979
/** The storage client used for setting an retrieving items from cache (window.localStorage or window.sessionStorage) */
8080
storage: Storage
8181
/** The key to use when storing the cache */
@@ -109,16 +109,16 @@ If you need to store more data in `localStorage`, you can override the `serializ
109109

110110
```js
111111
import { QueryClient } from '@tanstack/react-query';
112-
import { persistQueryClient } from 'react-query/persistQueryClient'
113-
import { createWebStoragePersister } from 'react-query/createWebStoragePersister'
112+
import { persistQueryClient } from '@tanstack/react-query-persist-client'
113+
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
114114

115115
import { compress, decompress } from 'lz-string';
116116

117117
const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity } } });
118118

119119
persistQueryClient({
120120
queryClient: connectionsQueryClient,
121-
persistor: createWebStoragePersister({
121+
persistor: createSyncStoragePersister({
122122
storage: window.localStorage,
123123
serialize: data => compress(JSON.stringify(data)),
124124
deserialize: data => JSON.parse(decompress(data)),

docs/plugins/persistQueryClient.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is set of utilities for interacting with "persisters" which save your query
77

88
## Build Persisters
99

10-
- [createWebStoragePersister](/plugins/createWebStoragePersister)
10+
- [createSyncStoragePersister](/plugins/createSyncStoragePersister)
1111
- [createAsyncStoragePersister](/plugins/createAsyncStoragePersister)
1212
- [create a custom persister](#persisters)
1313

@@ -57,7 +57,7 @@ the persister `removeClient()` is called and the cache is immediately discarded.
5757
### `persistQueryClientSave`
5858

5959
- Your query/mutation are [`dehydrated`](../reference/hydration#dehydrate) and stored by the persister you provided.
60-
- `createWebStoragePersister` and `createAsyncStoragePersister` throttle this action to happen at most every 1 second to save on potentially expensive writes. Review their documentation to see how to customize their throttle timing.
60+
- `createSyncStoragePersister` and `createAsyncStoragePersister` throttle this action to happen at most every 1 second to save on potentially expensive writes. Review their documentation to see how to customize their throttle timing.
6161

6262
You can use this to explicitly persist the cache at the moment(s) you choose.
6363

@@ -181,8 +181,8 @@ For this use-case, you can use the `PersistQueryClientProvider`. It will make su
181181

182182
```jsx
183183

184-
import { PersistQueryClientProvider } from 'react-query/persistQueryClient'
185-
import { createWebStoragePersister } from 'react-query/createWebStoragePersister'
184+
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
185+
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
186186

187187
const queryClient = new QueryClient({
188188
defaultOptions: {
@@ -192,7 +192,7 @@ const queryClient = new QueryClient({
192192
},
193193
})
194194

195-
const persister = createWebStoragePersister({
195+
const persister = createSyncStoragePersister({
196196
storage: window.localStorage,
197197
})
198198

docs/react-native.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { onlineManager } from '@tanstack/react-query'
2020

2121
onlineManager.setEventListener(setOnline => {
2222
return NetInfo.addEventListener(state => {
23-
setOnline(state.isConnected)
23+
setOnline(!!state.isConnected)
2424
})
2525
})
2626
```

0 commit comments

Comments
 (0)