Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@hmr:keep not honored if lang="ts" #571

Closed
Leftium opened this issue Jan 8, 2023 · 3 comments
Closed

@hmr:keep not honored if lang="ts" #571

Leftium opened this issue Jan 8, 2023 · 3 comments
Labels
bug Something isn't working edge-case has-workaround hmr wontfix This will not be worked on

Comments

@Leftium
Copy link

Leftium commented Jan 8, 2023

Describe the bug

If lang="ts" then @hmr:keep is not honored. (@hmr:keep-all still works).

Reproduction

  1. Clone https://github.com/Leftium/kit-bugs/tree/hmr
  2. Open /lang-ts route
  3. Click button to change value of count
  4. Trigger HMR (by changing increment amount)

Expected: value of count is preserved.

Actual: value of count is reset.

Notes:

  • The /lang-js route does not have this problem.
  • @hmr:keep-all works for both JS and TS.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 6.01 GB / 23.86 GB
  Binaries:
    Node: 18.9.0 - D:\dropbox\a\nodejs\64v18.9.0\node.EXE
    Yarn: 1.22.18 - D:\dropbox\home\.yarn\bin\yarn.CMD
  Browsers:
    Edge: Spartan (44.22621.963.0), Chromium (108.0.1462.76)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0
    @sveltejs/kit: ^1.0.0 => 1.0.1
    svelte: ^3.54.0 => 3.55.0
    vite: ^4.0.0 => 4.0.3

Severity

annoyance

Additional Information

Reference: https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#svelte-hmr

@bluwy bluwy transferred this issue from sveltejs/kit Jan 8, 2023
@bluwy
Copy link
Member

bluwy commented Jan 8, 2023

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:

  1. Hoping esbuild would support not stripping comments one day. It strips now due to performance reasons.
  2. Use 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 }).

@bluwy bluwy added bug Something isn't working hmr labels Jan 8, 2023
@dominikg
Copy link
Member

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 .

@dominikg
Copy link
Member

dominikg commented May 3, 2024

closing as wontfix, svelte-hmr is getting replaced by Svelte 5 native hmr support

@dominikg dominikg closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024
@dominikg dominikg added the wontfix This will not be worked on label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working edge-case has-workaround hmr wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants