Skip to content

Custom elements callbacks should untrack  #2039

@titoBouzout

Description

@titoBouzout

Describe the bug

Custom elements have numerous callbacks and these should untrack to avoid recursion. This is a bit tricky because a lot of DOM methods for manipulation could cause the callbacks to fire.

Your Example Website or App

https://playground.solidjs.com/anonymous/b6031b3f-7ce9-4322-a06f-31823340af8d

Steps to Reproduce the Bug or Issue

Testing code is the following

import { render } from "solid-js/web";
import { createSignal } from "solid-js";

const [read, write] = createSignal(true);

function recurse(name, ...args) {
  console.log(name, ...args);
  write(!read());
}

class CustomElement extends HTMLElement {
  static observedAttributes = ["string-attribute"];

  constructor() {
    super();
    recurse("constructor");
  }
  connectedCallback() {
    recurse("Custom element added to page.");
  }

  disconnectedCallback() {
    recurse("Custom element removed from page.");
  }

  adoptedCallback() {
    recurse("Custom element moved to new page.");
  }

  attributeChangedCallback(name, oldValue, newValue) {
    recurse(`Attribute ${name} has changed.`, oldValue, newValue);
  }
  set boolean(value) {
    recurse(`boolean has changed.`, value);
  }
}

customElements.define("custom-element", CustomElement);

render(
  () => () => (
    <custom-element string-attribute="lala" boolean={true}>
      Test
    </custom-element>
  ),
  document.getElementById("app")!,
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions