Skip to content

Commit 7449ad0

Browse files
committed
Merge remote-tracking branch 'tannerlinsley/beta' into feature/replace-import-specifier-codemod
2 parents 36c2d13 + f7cfe5f commit 7449ad0

File tree

11 files changed

+52
-50
lines changed

11 files changed

+52
-50
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/guides/migrating-to-react-query-4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ React.useEffect(() => mySideEffectHere(data), [data])
211211

212212
### `persistQueryClient` and the corresponding persister plugins are no longer experimental and have been renamed
213213

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.
214+
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.
215215

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

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

223223
+ import { persistQueryClient } from '@tanstack/react-query-persist-client'
224-
+ import { createWebStoragePersister } from '@tanstack/query-sync-storage-persister'
224+
+ import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
225225
+ import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
226226
```
227227

docs/guides/mutations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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

examples/react/offline/src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
import { ReactQueryDevtools } from "react-query/devtools";
1111
import toast, { Toaster } from "react-hot-toast";
1212

13-
import { PersistQueryClientProvider } from "react-query/persistQueryClient";
14-
import { createWebStoragePersister } from "react-query/createWebStoragePersister";
13+
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
14+
import { createSyncStoragePersister } from "@tanstack/query-sync-storage-persister";
1515
import {
1616
Link,
1717
Outlet,
@@ -23,7 +23,7 @@ import {
2323
import * as api from "./api";
2424
import { movieKeys, useMovie } from "./movies";
2525

26-
const persister = createWebStoragePersister({
26+
const persister = createSyncStoragePersister({
2727
storage: window.localStorage,
2828
});
2929

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"private": true,
33
"repository": "https://github.com/tanstack/query.git",
44
"scripts": {
5-
"install:csb": "npm run install --frozen-lockfile && node ./scripts/fix-package-json.js",
5+
"install:csb": "npm install --frozen-lockfile && node ./scripts/fix-package-json.js",
66
"test": "(is-ci && npm run test:ci) || npm run test:dev",
77
"test:ci": "npm run compile && npm run test:format && npm run test:eslint && npm run test:jest",
88
"test:dev": "npm run compile && npm run test:format && npm run test:eslint && npm run test:jest:dev",
99
"test:dev:17": "REACTJS_VERSION=17 jest --watch",
1010
"test:eslint": "lerna run test:eslint --stream --no-bail",
11-
"test:format": "npm run prettier --check",
11+
"test:format": "npm run prettier -- --check",
1212
"test:jest": "lerna run test:codemods --stream --no-bail && jest --config ./jest.config.ts",
1313
"test:jest:dev": "jest --config ./jest.config.ts --watch",
1414
"test:size": "npm run build && bundlewatch",
@@ -18,7 +18,8 @@
1818
"linkAll": "lerna exec 'npm run link' --parallel",
1919
"unlinkAll": "lerna exec 'npm run unlink' --parallel",
2020
"dev": "npm run watch",
21-
"prettier": "prettier \"packages/*/{src/**,examples/**/src/**}.{md,js,jsx,ts,tsx,json}\" --write",
21+
"prettier": "prettier \"packages/*/{src/**,examples/**/src/**}.{md,js,jsx,ts,tsx,json}\"",
22+
"prettier:write": "npm run prettier -- --write",
2223
"visualize": "lerna exec 'open build/stats-html.html'",
2324
"cipublish": "ts-node scripts/publish.ts",
2425
"compile": "lerna run compile --stream --no-bail"

packages/query-sync-storage-persister/src/__tests__/storageIsFull.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
QueryClient,
66
} from '@tanstack/query-core'
77
import { removeOldestQuery } from '@tanstack/react-query-persist-client'
8-
import { createWebStoragePersister } from '../index'
8+
import { createSyncStoragePersister } from '../index'
99
import { sleep } from '../../../../tests/utils'
1010

1111
function getMockStorage(limitSize?: number) {
@@ -39,14 +39,14 @@ function getMockStorage(limitSize?: number) {
3939
} as any as Storage
4040
}
4141

42-
describe('createWebStoragePersister ', () => {
42+
describe('createpersister ', () => {
4343
test('basic store and recover', async () => {
4444
const queryCache = new QueryCache()
4545
const mutationCache = new MutationCache()
4646
const queryClient = new QueryClient({ queryCache, mutationCache })
4747

4848
const storage = getMockStorage()
49-
const webStoragePersister = createWebStoragePersister({
49+
const persister = createSyncStoragePersister({
5050
throttleTime: 0,
5151
storage,
5252
})
@@ -64,9 +64,9 @@ describe('createWebStoragePersister ', () => {
6464
timestamp: Date.now(),
6565
clientState: dehydrate(queryClient),
6666
}
67-
webStoragePersister.persistClient(persistClient)
67+
persister.persistClient(persistClient)
6868
await sleep(1)
69-
const restoredClient = await webStoragePersister.restoreClient()
69+
const restoredClient = await persister.restoreClient()
7070
expect(restoredClient).toEqual(persistClient)
7171
})
7272

@@ -77,7 +77,7 @@ describe('createWebStoragePersister ', () => {
7777

7878
const N = 2000
7979
const storage = getMockStorage(N * 5) // can save 4 items;
80-
const webStoragePersister = createWebStoragePersister({
80+
const persister = createSyncStoragePersister({
8181
throttleTime: 0,
8282
storage,
8383
retry: removeOldestQuery,
@@ -99,9 +99,9 @@ describe('createWebStoragePersister ', () => {
9999
timestamp: Date.now(),
100100
clientState: dehydrate(queryClient),
101101
}
102-
webStoragePersister.persistClient(persistClient)
102+
persister.persistClient(persistClient)
103103
await sleep(10)
104-
const restoredClient = await webStoragePersister.restoreClient()
104+
const restoredClient = await persister.restoreClient()
105105
expect(restoredClient?.clientState.queries.length).toEqual(4)
106106
expect(
107107
restoredClient?.clientState.queries.find((q) => q.queryKey[0] === 'A'),
@@ -117,9 +117,9 @@ describe('createWebStoragePersister ', () => {
117117
timestamp: Date.now(),
118118
clientState: dehydrate(queryClient),
119119
}
120-
webStoragePersister.persistClient(updatedPersistClient)
120+
persister.persistClient(updatedPersistClient)
121121
await sleep(10)
122-
const restoredClient2 = await webStoragePersister.restoreClient()
122+
const restoredClient2 = await persister.restoreClient()
123123
expect(restoredClient2?.clientState.queries.length).toEqual(4)
124124
expect(
125125
restoredClient2?.clientState.queries.find((q) => q.queryKey[0] === 'A'),
@@ -135,7 +135,7 @@ describe('createWebStoragePersister ', () => {
135135

136136
const N = 2000
137137
const storage = getMockStorage(0)
138-
const webStoragePersister = createWebStoragePersister({
138+
const persister = createSyncStoragePersister({
139139
throttleTime: 0,
140140
storage,
141141
retry: removeOldestQuery,
@@ -149,9 +149,9 @@ describe('createWebStoragePersister ', () => {
149149
timestamp: Date.now(),
150150
clientState: dehydrate(queryClient),
151151
}
152-
webStoragePersister.persistClient(persistClient)
152+
persister.persistClient(persistClient)
153153
await sleep(10)
154-
const restoredClient = await webStoragePersister.restoreClient()
154+
const restoredClient = await persister.restoreClient()
155155
expect(restoredClient).toEqual(undefined)
156156
})
157157
})

packages/query-sync-storage-persister/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Storage {
1010
removeItem: (key: string) => void
1111
}
1212

13-
interface CreateWebStoragePersisterOptions {
13+
interface CreateSyncStoragePersisterOptions {
1414
/** The storage client used for setting and retrieving items from cache.
1515
* For SSR pass in `undefined`.
1616
*/
@@ -34,14 +34,14 @@ interface CreateWebStoragePersisterOptions {
3434
retry?: PersistRetryer
3535
}
3636

37-
export function createWebStoragePersister({
37+
export function createSyncStoragePersister({
3838
storage,
3939
key = `REACT_QUERY_OFFLINE_CACHE`,
4040
throttleTime = 1000,
4141
serialize = JSON.stringify,
4242
deserialize = JSON.parse,
4343
retry,
44-
}: CreateWebStoragePersisterOptions): Persister {
44+
}: CreateSyncStoragePersisterOptions): Persister {
4545
if (typeof storage !== 'undefined') {
4646
const trySave = (persistedClient: PersistedClient): Error | undefined => {
4747
try {

packages/react-query/src/__tests__/useQuery.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,7 @@ describe('useQuery', () => {
28662866
fallbackRender={({ error }) => (
28672867
<div>
28682868
<div>error boundary</div>
2869+
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
28692870
<div>{error?.message}</div>
28702871
</div>
28712872
)}

0 commit comments

Comments
 (0)