Re: [WICG/webcomponents] [scoped-registries] Concerns about non-construction of scoped elements (Issue #987)

I think the issue is largely due to library having no knowledge about how its components are registered, and therefore, has no way to create them.

This can be solved if we can look up the registered local name from a registry, namely, with `CustomElementRegistry.getName()` proposed in #566.

Your example can be changed into

```js
class ComponentB extends HTMLElement {
  static observedAttributes = ['foo'];
  attributeChangedCallback(name, oldValue, newValue) {
    if (name === 'foo' && newValue === '') {
      console.log('ComponentB: "foo" attribute added');
      try {
        let registry = this.getRootNode().registry || window.customElements;
        let tagName = registry.getName(ComponentA);
        this.appendChild(this.getRootNode().createElement(tagName));        
      } catch (error) {
        console.error(error.message);
      }
    }
  }
}
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/987#issuecomment-1505964591
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/987/1505964591@github.com>

Received on Wednesday, 12 April 2023 21:20:55 UTC