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 - Component Duplicated on Reload #137

Open
pfazzino opened this issue Apr 25, 2020 · 3 comments
Open

HMR - Component Duplicated on Reload #137

pfazzino opened this issue Apr 25, 2020 · 3 comments

Comments

@pfazzino
Copy link

Just started testing Parcel using Svelte. Wanted to use HMR so added

if (module.hot) { module.hot.accept() }

to main.js (doesn't matter where I add this) but got the same symptoms as that reported in #31 with output being appended on save. It's not just when editing the main.js though, any save on the svelte component causes the output to be appended.

See example - https://github.com/pfazzino/parcelsveltetest

@benhormann
Copy link

if (module.hot) {
  module.hot.dispose(() => {
    app.$destroy();
  });
  module.hot.accept();
}

Credit: figured this out from rixo's templates https://github.com/rixo/svelte-hmr.

@pfazzino
Copy link
Author

pfazzino commented Jun 20, 2020

Yup good fix. This isn't full hmr as state isn't preserved between reloads but it's still a really valuable feature. Is the lack of state preservation a limitation of svelte itself until hmr is officially supported sveltejs/svelte#3632

@benhormann
Copy link

Kinda, rixo has got hmr working well enough in webpack / rollup, and even experimenting with snowpack.

Stores are preserved even though component state isn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants