Description
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 by on:event={handler}
), who were stored on cmp.$$.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 :
targetCmp.$$.on_hmr = []
I edited this line of svelte-hooks.js in order to keep my hooks :
targetCmp.$$.on_hmr = targetCmp.$$.on_hmr || [];
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