Closed Leftium closed 6 months ago
That's because vitePreprocess
uses esbuild
to transpile TS to JS. esbuild unfortunately removes (most) comments by default, so the comment was likely stripped before svelte-hmr sees them.
I'm not really sure how this can be fixed, other than:
svelte-preprocess
and typescript
to preprocess lang="ts"
no2 can be used to workaround in the meantime if you rely on this feature. You can turn off script processing in vitePreprocess
specifically with vitePreprocess({ script: false })
.
esbuild unconditionally stripping comments is a bit of a bummer, but as mentioned already you can switch to svelte-preprocess if you need this behavior.
You can also enable it globally with a flag in svelte.config.js vitePlugin.hmr
, but preserving local state during hmr is not without risk, see https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state .
closing as wontfix, svelte-hmr is getting replaced by Svelte 5 native hmr support
Describe the bug
If
lang="ts"
then@hmr:keep
is not honored. (@hmr:keep-all
still works).Reproduction
count
Expected: value of
count
is preserved.Actual: value of
count
is reset.Notes:
@hmr:keep-all
works for both JS and TS.Logs
No response
System Info
Severity
annoyance
Additional Information
Reference: https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#svelte-hmr