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
Copy file name to clipboardExpand all lines: packages/vite-plugin-svelte/README.md
+49-1Lines changed: 49 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,54 @@ const vitePluginCoolCss = {
86
86
87
87
Check out [windicss](https://github.com/windicss/vite-plugin-windicss/blob/517eca0cebc879d931c6578a08accadfb112157c/packages/vite-plugin-windicss/src/index.ts#L167)
88
88
89
+
## FAQ
90
+
91
+
### Why is component state reset on hmr update?
92
+
93
+
Preservation of local component state after js updates is disabled to avoid unpredictable and errorprone behavior. You can read more about it [here](https://github.com/rixo/svelte-hmr#preservation-of-local-state).
94
+
95
+
Please note that if you only edit the `style` node, a separate css update can be applied where component state is 100% preserved.
96
+
97
+
### What is the recommended node order for svelte sfc files?
98
+
99
+
The `<style>` node should be last to ensure optimal hmr results.
100
+
This is also the default order with [prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte)
101
+
102
+
Good:
103
+
104
+
```sveltehtml
105
+
<script></script>
106
+
<div></div>
107
+
<style></style>
108
+
```
109
+
110
+
Bad:
111
+
112
+
```sveltehtml
113
+
<script></script>
114
+
<style></style>
115
+
<!-- this template element is below the style node and may cause extra js hmr updates -->
116
+
<div></div>
117
+
```
118
+
119
+
### Why isn't vite detecting my imports correctly in `.svelte` files with typescript?
120
+
121
+
You have to use the `lang="ts"` attribute for vite to parse it. Never `lang="typescript"` or `type="text/typescript"`
0 commit comments