-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Make $$.on_hmr public (or a way to detect HMR update) #66
Comments
My bad I feel so stupid. So sometinh like that : let comp = new Comp(...);
comp.$$.on_hmr && comp.$$.on_hmr.push( (_: any) => {
return (c: SvelteComponent) => restart_all_callback(c);
}); Just one question before closing : do |
Not sure which changes to svelte you are talking about. If you intend to send a PR to svelte itself, is there a feature request, open issue or PR you can link to? In general $$ is not meant for public use or part of a stable api for public consumption. Please see vite docs for how to listen to update events: https://vitejs.dev/guide/api-hmr.html#hot-on-event-cb That being said this is dev only, so you could do introspection like in your example and assume that if on_hmr exists it works the way it currently does. It may break the dev workflow but not production builds if svelte/svelte-hmr change in ways that make it incompatible. |
Thanks for your response. The issue is here : sveltejs/svelte#2837 |
@adiguba There's no immediate plan to make Make sure you're subscribed to #57, as we'll issue some notice there if for some reason it comes to change. In any case, if your usage of it is to support a feature that gets included in Svelte itself, you can be sure we won't change it without proper synchronisation to make sure everything keeps working. |
also please note that svelte-hmr is currently a dev time addon over svelte. svelte itself is completely unaware of svelte-hmr and in its current major version (svelte3) is should stay that way. A future major version of svelte may incorporate hmr features directly so svelte-hmr as a separate package will no longer be needed. Given this and the fact that svelte on:* support might need further discussions i encourage you to get in touch on svelte discord #contributing before investing a lot of work in a PR. |
Thanks for your advices ! |
Hello,
I'm working on some change on the way Svelte manage the event-handler via the
on:event
directive.My changes work fine as long as the code is not reloaded via HMR...
In fact my code process the handlers added to the component, via
.$on()
(called byon:event={handler}
), who were stored oncmp.$$.callbacks
.But when the code is refreshed via HMR, the component is fully recreated with props, and
cmp.$$.callbacks
is updated, but I have no way to detect that, so my code cannot (re)process the handlers correctly.I need a way to know that the component was reloaded in order to reprocess
cmp.$$.callback
.I see this comment about the undocumented hook
cmp.$$.on_hmr
: #57 (comment)But it seem it didn't work on my case, because this field is initialized when svelte-hmr instrument the component (line 216 of svelte-hooks.js), and it will overwritte my own hook initialized when my component is created :
I edited this line of svelte-hooks.js in order to keep my hooks :
It's seem to work for me, but I don't know how Svelte-HMR works nor the impact of this change.
Or is there another way to detect code reload ?
Thanks
The text was updated successfully, but these errors were encountered: