Skip to content

Commit 1078bce

Browse files
authored
refactor: deprecate createSyncStoragePersister (#9316)
1 parent 20120ae commit 1078bce

File tree

17 files changed

+44
-34
lines changed

17 files changed

+44
-34
lines changed

docs/framework/react/plugins/createAsyncStoragePersister.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ bun add @tanstack/query-async-storage-persister @tanstack/react-query-persist-cl
3333

3434
- Import the `createAsyncStoragePersister` function
3535
- Create a new asyncStoragePersister
36-
- you can pass any `storage` to it that adheres to the `AsyncStorage` interface - the example below uses the async-storage from React Native
36+
- you can pass any `storage` to it that adheres to the `AsyncStorage` interface - the example below uses the async-storage from React Native.
37+
- storages that read and write synchronously, like `window.localstorage`, also adhere to the `AsyncStorage` interface and can therefore also be used with `createAsyncStoragePersister`.
3738
- Wrap your app by using [`PersistQueryClientProvider`](../persistQueryClient.md#persistqueryclientprovider) component.
3839

3940
```tsx
@@ -99,10 +100,11 @@ interface CreateAsyncStoragePersisterOptions {
99100
retry?: AsyncPersistRetryer
100101
}
101102

102-
interface AsyncStorage {
103-
getItem: (key: string) => Promise<string | null>
104-
setItem: (key: string, value: string) => Promise<unknown>
105-
removeItem: (key: string) => Promise<void>
103+
interface AsyncStorage<TStorageValue = string> {
104+
getItem: (key: string) => MaybePromise<TStorageValue | undefined | null>
105+
setItem: (key: string, value: TStorageValue) => MaybePromise<unknown>
106+
removeItem: (key: string) => MaybePromise<void>
107+
entries?: () => MaybePromise<Array<[key: string, value: TStorageValue]>>
106108
}
107109
```
108110

docs/framework/react/plugins/createSyncStoragePersister.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ id: createSyncStoragePersister
33
title: createSyncStoragePersister
44
---
55

6+
## Deprecated
7+
8+
This plugin is deprecated and will be removed in the next major version.
9+
You can simply use ['@tanstack/query-async-storage-persister'](../createAsyncStoragePersister.md) instead.
10+
611
## Installation
712

813
This utility comes as a separate package and is available under the `'@tanstack/query-sync-storage-persister'` import.

docs/framework/react/plugins/persistQueryClient.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ For this use-case, you can use the `PersistQueryClientProvider`. It will make su
184184

185185
```tsx
186186
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
187-
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
187+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
188188

189189
const queryClient = new QueryClient({
190190
defaultOptions: {
@@ -194,7 +194,7 @@ const queryClient = new QueryClient({
194194
},
195195
})
196196

197-
const persister = createSyncStoragePersister({
197+
const persister = createAsyncStoragePersister({
198198
storage: window.localStorage,
199199
})
200200

docs/framework/vue/guides/mutations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const vueQueryOptions: VueQueryPluginOptions = {
8181
clientPersister: (queryClient) => {
8282
return persistQueryClient({
8383
queryClient,
84-
persister: createSyncStoragePersister({ storage: localStorage }),
84+
persister: createAsyncStoragePersister({ storage: localStorage }),
8585
})
8686
},
8787
clientPersisterOnSuccess: (queryClient) => {

examples/angular/basic-persister/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@angular/platform-browser": "^20.0.0",
1616
"@tanstack/angular-query-experimental": "^5.81.2",
1717
"@tanstack/angular-query-persist-client": "^5.62.7",
18-
"@tanstack/query-sync-storage-persister": "^5.81.2",
18+
"@tanstack/query-async-storage-persister": "^5.81.2",
1919
"rxjs": "^7.8.2",
2020
"tslib": "^2.8.1",
2121
"zone.js": "0.15.0"

examples/angular/basic-persister/src/app/app.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
withDevtools,
66
} from '@tanstack/angular-query-experimental'
77
import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
8-
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
8+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
99
import type { ApplicationConfig } from '@angular/core'
1010

11-
const localStoragePersister = createSyncStoragePersister({
11+
const localStoragePersister = createAsyncStoragePersister({
1212
storage: window.localStorage,
1313
})
1414

examples/react/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test:eslint": "eslint ./src"
1010
},
1111
"dependencies": {
12-
"@tanstack/query-sync-storage-persister": "^5.81.2",
12+
"@tanstack/query-async-storage-persister": "^5.81.2",
1313
"@tanstack/react-query": "^5.81.2",
1414
"@tanstack/react-query-devtools": "^5.81.2",
1515
"@tanstack/react-query-persist-client": "^5.81.2",

examples/react/basic/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import ReactDOM from 'react-dom/client'
33
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
44
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
5-
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
5+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
66
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
77

88
const queryClient = new QueryClient({
@@ -13,7 +13,7 @@ const queryClient = new QueryClient({
1313
},
1414
})
1515

16-
const persister = createSyncStoragePersister({
16+
const persister = createAsyncStoragePersister({
1717
storage: window.localStorage,
1818
})
1919

examples/react/eslint-legacy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint ./src/**/*.tsx"
1010
},
1111
"dependencies": {
12-
"@tanstack/query-sync-storage-persister": "^5.81.2",
12+
"@tanstack/query-async-storage-persister": "^5.81.2",
1313
"@tanstack/react-query": "^5.81.2",
1414
"@tanstack/react-query-devtools": "^5.81.2",
1515
"@tanstack/react-query-persist-client": "^5.81.2",

examples/react/eslint-legacy/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import ReactDOM from 'react-dom/client'
33
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
44
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
5-
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
5+
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
66
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
77

88
const queryClient = new QueryClient({
@@ -13,7 +13,7 @@ const queryClient = new QueryClient({
1313
},
1414
})
1515

16-
const persister = createSyncStoragePersister({
16+
const persister = createAsyncStoragePersister({
1717
storage: window.localStorage,
1818
})
1919

0 commit comments

Comments
 (0)