Skip to content

Commit f39377e

Browse files
committed
chore(query core): upgrade, fix typo
1 parent 0154087 commit f39377e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

docs/src/pages/guides/mutations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Here's an example of a mutation that adds a new todo the server:
3737
A mutation can only be in one of the following states at any given moment:
3838

3939
- `isIdle` or `status === 'idle' - The mutation is currently idle or in a fresh/reset state
40-
- `isLoading` or `status === 'loading' - The mutation is currently running
40+
- `isLoading` or `status === 'loading' -` The mutation is currently running
4141
- `isError` or `status === 'error'` - The mutation encountered an error
42-
- `isSuccess` or `status === 'success' - The mutation was successful and mutation data is available
42+
- `isSuccess` or `status === 'success'` - The mutation was successful and mutation data is available
4343

4444
Beyond those primary state, more information is available depending on the state the mutation:
4545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Consider the following example where we would ideally want to increment a pageIn
3030
const fetchProjects = (page = 0) => fetch('/api/projects?page=' + page)
3131
</script>
3232

33-
<Query options={{ queryKey: ['projects', page], queryFn: () => fetchProjects(page) }}>
33+
<Query options={{ queryKey: ['projects', page], queryFn: () => fetchProjects(page), keepPreviousData: true }}>
3434
<div slot="query" let:queryResult>
3535
{#if queryResult.status === 'loading'}
3636
Loading...

docs/src/pages/guides/queries.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ const result = useQuery('todos', fetchTodoList)
3030

3131
The `result` object contains a few very important states you'll need to be aware of to be productive. A query can only be in one of the following states at any given moment:
3232

33-
- `isLoading` or `status === 'loading' - The query has no data and is currently fetching
33+
- `isLoading` or `status === 'loading'` - The query has no data and is currently fetching
3434
- `isError` or `status === 'error'` - The query encountered an error
35-
- `isSuccess` or `status === 'success' - The query was successful and data is available
36-
- `isIdle` or `status === 'idle' - The query is currently disabled (you'll learn more about this in a bit)
35+
- `isSuccess` or `status === 'success'` - The query was successful and data is available
36+
- `isIdle` or `status === 'idle'` - The query is currently disabled (you'll learn more about this in a bit)
3737

3838
Beyond those primary state, more information is available depending on the state the query:
3939

4040
- `error` - If the query is in an `isError` state, the error is available via the `error` property.
4141
- `data` - If the query is in a `success` state, the data is available via the `data` property.
4242
- `isFetching` - In any state, if the query is fetching at any time (including background refetching) `isFetching` will be `true`.
4343

44-
For **most** queries, it's usually sufficient to check for the `isLoading` state, then the `isError` state, then finally, assume that the data is avaiable and render the successful state:
44+
For **most** queries, it's usually sufficient to check for the `isLoading` state, then the `isError` state, then finally, assume that the data is available and render the successful state:
4545

4646
```markdown
4747

src/queryCore/persist-localstorage-experimental/index.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ export function persistWithLocalStorage(
3131
buster = '',
3232
}: Options = {}
3333
) {
34-
const saveCache = throttle(() => {
35-
const storageCache: LocalStorageCache = {
36-
buster,
37-
timestamp: Date.now(),
38-
cacheState: dehydrate(queryClient),
39-
}
34+
if (typeof window !== 'undefined') {
35+
// Subscribe to changes
36+
const saveCache = throttle(() => {
37+
const storageCache: LocalStorageCache = {
38+
buster,
39+
timestamp: Date.now(),
40+
cacheState: dehydrate(queryClient),
41+
}
42+
43+
localStorage.setItem(localStorageKey, JSON.stringify(storageCache))
44+
}, throttleTime)
4045

41-
localStorage.setItem(localStorageKey, JSON.stringify(storageCache))
42-
}, throttleTime)
46+
queryClient.getQueryCache().subscribe(saveCache)
4347

44-
if (typeof localStorage !== 'undefined') {
48+
// Attempt restore
4549
const cacheStorage = localStorage.getItem(localStorageKey)
4650

4751
if (!cacheStorage) {
@@ -58,9 +62,9 @@ export function persistWithLocalStorage(
5862
} else {
5963
hydrate(queryClient, cache.cacheState)
6064
}
65+
} else {
66+
localStorage.removeItem(localStorageKey)
6167
}
62-
63-
queryClient.getQueryCache().subscribe(saveCache)
6468
}
6569
}
6670

0 commit comments

Comments
 (0)