m- icon indicating copy to clipboard operation
m- copied to clipboard

The connectedCallback runs multiple times

Open Danny-Engelman opened this issue 2 years ago • 2 comments

Like the subject says, when you move/drag drop elements in the DOM, the connectedCallback will run again.

Danny-Engelman avatar Apr 05 '22 09:04 Danny-Engelman

I'd need more info @Danny-Engelman. Is this in regards to a specific component or all of the Custom Element components?

jfbrennan avatar Apr 26 '22 23:04 jfbrennan

The connectedCallback runs for every (re)placement in the DOM

https://jsfiddle.net/WebComponents/mc1o94kw/

<script>
  customElements.define('my-element', class extends HTMLElement {
    connectedCallback() {
      this.innerHTML += "<h1>Click me!</h1>";
      this.onclick = (evt) => document.body.append(this);
    }
  });
</script>

<my-element></my-element>

Danny-Engelman avatar Apr 27 '22 08:04 Danny-Engelman