Skip to content

Commit 373e24b

Browse files
Add migration docs
1 parent e3bba4a commit 373e24b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

docs/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
{
128128
"label": "SSR & SvelteKit",
129129
"to": "framework/svelte/ssr"
130+
},
131+
{
132+
"label": "Migrate from v5 to v6",
133+
"to": "framework/svelte/migrate-from-v5-to-v6"
130134
}
131135
]
132136
},
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Overview
2+
3+
While Svelte v5 has legacy compatibility with the stores syntax from Svelte v3/v4, it has been somewhat buggy and unreliable for this TanStack Query adapter. The `@tanstack/svelte-query` v6 adapter fully migrates to runes syntax.
4+
5+
## Installation
6+
7+
Run `pnpm add @tanstack/svelte-query@latest` (or your package manager's equivalent).
8+
9+
> Note that `@tanstack/svelte-query` v6 depends on `@tanstack/query-core` v5.
10+
11+
## Thunks
12+
13+
Like the Solid adapter, most functions for the Svelte adapter now require options to be provided as a "thunk" (`() => options`) to maintain reactivity.
14+
15+
```diff
16+
-const query = createQuery({
17+
+const query = createQuery(() => ({
18+
queryKey: ['todos'],
19+
queryFn: () => fetchTodos(),
20+
-})
21+
+}))
22+
```
23+
24+
## Accessing Properties
25+
26+
Given the adapter no longer uses stores, it is no longer necessary to prefix with `$`.
27+
28+
```diff
29+
-{#if $todos.isSuccess}
30+
+{#if todos.isSuccess}
31+
<ul>
32+
- {#each $todos.data.items as item}
33+
+ {#each todos.data.items as item}
34+
<li>{item}</li>
35+
{/each}
36+
</ul>
37+
{/if}
38+
```
39+
40+
## Disabling Legacy Mode
41+
42+
If your component has any stores, it might not properly switch to runes mode. You can ensure your application is using runes in two ways:
43+
44+
### On a per-file basis
45+
46+
In each `.svelte` file, once you have migrated to runes, add `<svelte:options runes={true} />`. This is better for large applications requiring gradual migration.
47+
48+
### On an project-wide basis
49+
50+
In your `svelte.config.js`, add the following to config:
51+
52+
```json
53+
compilerOptions: {
54+
runes: true,
55+
},
56+
```
57+
58+
This can be added once you've 100% eradicated stores syntax from your app.

docs/framework/svelte/overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: Overview
55

66
The `@tanstack/svelte-query` package offers a 1st-class API for using TanStack Query via Svelte.
77

8+
> Migrating from stores to the runes syntax? See the [migration guide](../migrate-from-v5-to-v6).
9+
810
## Example
911

1012
Include the QueryClientProvider near the root of your project:

0 commit comments

Comments
 (0)