-
Notifications
You must be signed in to change notification settings - Fork 922
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
adding svelte-hmr #1223
adding svelte-hmr #1223
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/3r5qld33m |
Hmm, Cannot find module 'svelte-hmr/runtime/hot-api-esm.js' may be an issue in how you were linking these files during development. When you go to install the package normally, there should be no difference in your node_modules directory between a peerDep and a true dep. |
Indeed, when installing from file system, it seems to work like a charm :-) npx create-snowpack-app svelte-app-hot --template @snowpack/app-template-svelte --use-yarn
cd svelte-app-hot
yarn add -D ../snowpack/plugins/plugin-svelte
yarn
yarn start I'm adding docs about options tomorrow. |
Yup, ran this myself and it runs well! I see only App.js & App.css being updated in the network panel, the root HMR acceptance at |
mostly just curious: is there any sort of "fast refresh" story for Svelte, where HMR updates preserve component state? |
Well... I don't have much experience with fast refresh, but I thought It only preserves state of parent components (easy, they're unaffected) and the component being refreshed itself, but any children of the affected component are recreated with no state transfer whatsoever. That's kind of a technical limitation, it would be prohibitively complicated to try to find & pair child components with their previous self. And very unstable since a component content can very well change entirely upon a HMR update... Does fast refresh do more than that? Anyway, you remind me that there is one thing that I have overlooked here. Since the Svelte plugin already had well working HMR for CSS, I left it untouched, but actually Just looked into this, and the only thing I'm missing from Snowpack HMR to enable support for "CSS only" updates is the bubbled info we briefly discussed a while ago. It's still not possible to know that from an accept handler in Snowpack, or did I miss something? |
Oh right, can you remind me / link me to this convo again? It's been a while
You can see this more clearly in the latest Svelte template, if you rebase onto master. When you make a change to That was the behavior I was seeing locally, anyway! |
I had hidden the link behind a word ;) FredKSchott/esm-hmr#13 And yes, I'm checking with master. |
The template on master contains a broken reactive statement that resets the counter to 0 on HMR updates... and a memory leak. I've submitted a PR. With that, state preservation should be visible. |
Thanks for the fix! lol my Svelte ability is clearly lacking, luckily that code has only been public for ~12 hours. |
Okay, caught up and yea, I'm +1 on the |
Nice!! Webpack has no direct equivalent AFAIK. It might be possible to track down the information with global HMR event listeners but I never really tried... CSS only updates is a kind of a luxury feature, so I'm just falling back to full replace without much remorse if the underlying HMR engine doesn't offer it. Actually, thanks to this change, Snowpack is probably the only other system, with
I think I'm good on my side, so removing the draft statut of the PR. Tell me what more do you think we need? Ah! And be careful, I've merged the bubbled branch in this PR, so I you merge this one you'll get both... That was probably not needed in hindsight 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Changes
This adds svelte-hmr to the Svelte plugin. This allows for component-level, state preserving HMR in Svelte apps.
This is still a little bit WIP, but I could use some help & directions.
Testing
No tests, yet... Any direction about what's needed?
Docs
TODO
Discussion
The main problem I'm facing is that I haven't found how to make
svelte-hmr
a dependency of the plugin. If I add it as a normal dep of the plugin, I get the following error when launching Snowpack:svelte-hmr
needs to be installed in the user's project for this to work... so I've just added it as a peerDependency for now.Any idea how I can fix this? Or do you think it would be best that user keeps the choice to install
svelte-hmr
or not?