Skip to content

Commit 84c8329

Browse files
committed
chore(core): stop returning cancelledError on reset during fetch, fix docs
1 parent f47da59 commit 84c8329

File tree

7 files changed

+24
-7
lines changed

7 files changed

+24
-7
lines changed

docs/src/pages/guides/dependent-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: dependent-queries
33
title: Dependent Queries
44
---
55

6-
Dependent (or serial) queries depend on previous ones to finish before they can execute. To achive this, it's as easy as using the `enabled` option to tell a query when it is ready to run:
6+
Dependent (or serial) queries depend on previous ones to finish before they can execute. To achieve this, it's as easy as using the `enabled` option to tell a query when it is ready to run:
77

88
```markdown
99
<script>

docs/src/pages/plugins/persist-localstorage.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@ This plugin comes packaged with `svelte-query` and is available under the `@svel
1111

1212
## Usage
1313

14-
Import the `persistWithLocalStorage` function, and pass it your `QueryClient` instance!
14+
Import the `persistWithLocalStorage` function, and pass it your `QueryClient` instance (with a `cacheTime` set)!
1515

1616
```js
1717
import { persistWithLocalStorage } from '@sveltestack/svelte-query'
1818

19-
const queryClient = new QueryClient()
19+
const queryClient = new QueryClient({
20+
defaultOptions: {
21+
queries: {
22+
cacheTime: 1000 * 60 * 60 * 24 // 24 hours
23+
}
24+
}
25+
})
2026

2127
persistWithLocalStorage(queryClient)
2228
```
2329

30+
**IMPORTANT** - for persist to work properly, you need to pass `QueryClient` a `cacheTime` value to override the default during hydration (as shown above).
31+
32+
If it is not set when creating the `QueryClient` instance, it will default to `300000` (5 minutes) for hydration, and local storage will be discarded after 5 minutes of inactivity. This is the default garbage collection behavior.
33+
34+
It should be set as the same value or higher than persistWithLocalStorage's `maxAge` option. E.g. if `maxAge` is 24 hours (the default) then `cacheTime` should be 24 hours or higher. If lower than `maxAge`, garbage collection will kick in and discard the local storage earlier than expected.
35+
36+
You can also pass it `Infinity` to disable garbage collection behavior entirely.
37+
2438
## How does it work?
2539

2640
As you use your application:

docs/src/pages/reference/useMutation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ mutate(variables, {
7979
- Optional
8080
- The variables object to pass to the `mutationFn`.
8181
- Remaining options extend the same options described above in the `useMutation` hook.
82+
- If you make multiple requests, `onSuccess` will fire only after the latest call you've made.
8283
- `mutateAsync: (variables: TVariables, { onSuccess, onSettled, onError }) => Promise<TData>`
8384
- Similar to `mutate` but returns a promise which can be awaited.
8485
- `status: string`

docs/src/pages/reference/useQuery.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const result = useQuery({
6161
- `queryKey: string | unknown[]`
6262
- **Required**
6363
- The query key to use for this query.
64-
- The query key will be hashed into a stable hash. See [Query Keys](./guides/query-keys) for more information.
64+
- The query key will be hashed into a stable hash. See [Query Keys](../guides/query-keys) for more information.
6565
- The query will automatically update when this key changes (as long as `enabled` is not set to `false`).
6666
- `queryFn: (context: QueryFunctionContext) => Promise<TData>`
6767
- **Required, but only if no default query function has been defined**
@@ -71,7 +71,7 @@ const result = useQuery({
7171
- Must return a promise that will either resolves data or throws an error.
7272
- `enabled: boolean`
7373
- Set this to `false` to disable this query from automatically running.
74-
- Can be used for [Dependent Queries](./guides/queries#dependent-queries).
74+
- Can be used for [Dependent Queries](./guides/dependent-queries).
7575
- `retry: boolean | number | (failureCount: number, error: TError) => boolean`
7676
- If `false`, failed queries will not retry by default.
7777
- If `true`, failed queries will retry infinitely.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sveltestack/svelte-query",
33
"private": false,
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Svelte",
66
"license": "MIT",
77
"svelte": "svelte/index.js",

src/queryCore/core/onlineManager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ class OnlineManager extends Subscribable {
5353
this.setEventListener(onOnline => {
5454
// Listen to online
5555
window.addEventListener('online', onOnline, false)
56+
window.addEventListener('offline', onOnline, false)
5657

5758
return () => {
5859
// Be sure to unsubscribe if a new handler is set
5960
window.removeEventListener('online', onOnline)
61+
window.removeEventListener('offline', onOnline)
6062
}
6163
})
6264
}

src/queryCore/core/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class Query<
228228

229229
destroy(): void {
230230
this.clearGcTimeout()
231-
this.cancel()
231+
this.cancel({ silent: true })
232232
}
233233

234234
reset(): void {

0 commit comments

Comments
 (0)