You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* refactor: remove type-fest as a dependency
only used for the Promisable type, which is easy to recreate
* feat(persistQueryClient): error handling strategies for persist plugins
* feat(persistQueryClient): error handling strategies for persist plugins
adapt tests
* make handlePersistError return null to stop retries
if null is returned, which is also the default strategy, the webstorage entry will be removed completely.
* test for default behaviour
* async version for persist error handling
to make sync and async compatible, persist version must also throw an error to abort
* make sure that async persister can accept sync error handlers
* undefined errorStrategy, or return undefined from it, will just not persist anymore
* rename to retry + documentation
* improve docs
Copy file name to clipboardExpand all lines: docs/src/pages/plugins/createAsyncStoragePersister.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,10 @@ persistQueryClient({
37
37
})
38
38
```
39
39
40
+
## Retries
41
+
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.
Copy file name to clipboardExpand all lines: docs/src/pages/plugins/createWebStoragePersister.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,34 @@ persistQueryClient({
34
34
})
35
35
```
36
36
37
+
## Retries
38
+
39
+
Persistence can fail, e.g. if the size exceeds the available space on the storage. Errors can be handled gracefully by providing a `retry` function to the persister.
40
+
41
+
The retry function receives the `persistedClient` it tried to save, as well as the `error` and the `errorCount` as input. It is expected to return a _new_`PersistedClient`, with which it tries to persist again. If _undefined_ is returned, there will be no further attempt to persist.
42
+
43
+
```ts
44
+
exporttypePersistRetryer= (props: {
45
+
persistedClient:PersistedClient
46
+
error:Error
47
+
errorCount:number
48
+
}) =>PersistedClient|undefined
49
+
```
50
+
51
+
### Predefined strategies
52
+
53
+
Per default, no retry will occur. You can use one of the predefined strategies to handle retries. They can be imported `from'react-query/persistQueryClient'`:
54
+
55
+
- `removeOldestQuery`
56
+
- will return a new `PersistedClient` with the oldest query removed.
There is a limit to the amount of data which can be stored in `localStorage`.
107
+
There is a limit to the amount of data which can be stored in `localStorage`.
78
108
If you need to store more data in `localStorage`, you can override the `serialize` and `deserialize` functions to compress and decrompress the data using a library like [lz-string](https://github.com/pieroxy/lz-string/).
0 commit comments