Description
What happens when a node is replaced by another one?
Let's take the following example:
const routerOutletEl = document.createElement('div');
const router = new HyperHTMLApp();
const renderRoute = hyperHTML.bind(routerOutletEl);
function handler1() {
// Noop
}
function handler2() {
// Noop
}
// First render
renderRoute`<my-comp onevent=${handler1} />`
// Update
renderRoute`<another-comp onanotherevent=${handler2} />`
What happens with the instance of <my-comp>
? Is it gargage-collected or is always there in memory ready to come back? The same question arises for the event handler (I'm not using DOM handleEvent
on purpose because I prefer this way).
TLDR; I'm wondering if hyperHTML already cleans up the stuff for me when elements are "unmounted" or better disconnected, or I have to do it myself somehow. Should I add a disconnectedCallback
in my CE and remove the event listeners?
The question arised because I was trying the Performance monitor in Chrome and going back&forward between home and a card in https://ygo.now.sh/ seems to always increase DOM Nodes and event listeners.