Skip to content

ondestroy in custom elements #1152

@Rich-Harris

Description

@Rich-Harris

Trying to wrap my head round this while looking at #1117. I don't think ondestroy should be called for a custom element when it's detached (with disconnectedCallback) because it means something slightly different in custom element land — it can be a temporary thing (the element can be reinserted), whereas destroy is permanent. In other words, destroy should still be called manually for custom elements inserted with e.g. document.body.innerHTML = '<x-app/>'.

But when we have a situation like this...

{{#if foo}}
  <x-thing/>
{{/if}}

...and x-thing is a Svelte custom element, we probably do want to call ondestroy, since there's basically no sensible way to do that programmatically.

Which means we need a reliable way to distinguish between Svelte custom elements and non-Svelte custom elements (where destroy could potentially mean something different, meaning duck typing isn't necessarily reliable).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions