Skip to content

Commit 86161ca

Browse files
docs(svelte-query): Add recommended defaults to prefetchQuery setup (#4815)
* Add recommended defaults to prefetch example * Move SSR docs up in sidebar
1 parent 832d4fb commit 86161ca

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

docs/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,13 @@
695695
"label": "Installation",
696696
"to": "svelte/installation"
697697
},
698-
{
699-
"label": "Reactivity",
700-
"to": "svelte/reactivity"
701-
},
702698
{
703699
"label": "SSR & SvelteKit",
704700
"to": "svelte/ssr"
701+
},
702+
{
703+
"label": "Reactivity",
704+
"to": "svelte/reactivity"
705705
}
706706
]
707707
},

docs/svelte/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Include the QueryClientProvider near the root of your project:
1111

1212
```markdown
1313
<script lang="ts">
14-
import { QueryClientProvider, QueryClient } from '@tanstack/svelte-query'
14+
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
1515
import Example from './lib/Example.svelte'
1616

1717
const queryClient = new QueryClient()

docs/svelte/ssr.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ SvelteKit defaults to rendering routes with SSR. Because of this, you need to di
99

1010
The recommended way to achieve this is to use the `browser` module from SvelteKit in your `QueryClient` object. This will not disable `queryClient.prefetchQuery()`, which is used in one of the solutions below.
1111

12+
**src/routes/+layout.svelte**
13+
1214
```markdown
1315
<script lang="ts">
1416
import { browser } from '$app/environment'
15-
import { QueryClient } from '@tanstack/svelte-query'
17+
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
1618

1719
const queryClient = new QueryClient({
1820
defaultOptions: {
@@ -83,11 +85,19 @@ Svelte Query supports prefetching queries on the server. Using this setup below,
8385
**src/routes/+layout.ts**
8486

8587
```ts
88+
import { browser } from '$app/environment'
8689
import { QueryClient } from '@tanstack/svelte-query'
8790
import type { LayoutLoad } from './$types'
8891

8992
export const load: LayoutLoad = async () => {
90-
const queryClient = new QueryClient()
93+
const queryClient = new QueryClient({
94+
defaultOptions: {
95+
queries: {
96+
enabled: browser,
97+
},
98+
},
99+
})
100+
91101
return { queryClient }
92102
}
93103
```

0 commit comments

Comments
 (0)