Skip to content

Automatic cleanup of nodes and event listeners #269

Closed
@jiayihu

Description

@jiayihu

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.

screen shot 2018-09-07 at 12 28 41

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions