Re: [WICG/webcomponents] [scoped-registries] Interaction with declarative shadow DOM (#914)

Question on the use of `attachInternals()` in the description of this issue. Shadow Roots can be bound to any element, whereas `attachInternals()` can only be bound to custom elements, IIUC. Does this means that not all shadow roots can have their scoped registries set after the fact?

This may be way late in the process (or maybe just in time 😉), but what if rather than or in addition to applying a scoped registry at attach time:

```js
this.attachShadow({mode: 'open', registry});
```

We were able to create a shadow root _with_ a scoped registry, much like the `shadowrootregistry` implies in the description. Creating a shadow root in this way would then include a `registry` on the `shadowRoot` that you could register elements on, a la:

```js
import { Button } from './button.js';
import { Input } from './input.js';

// ...

this.attachShadow({mode: 'open', registryType: 'scoped'}); // or some nicer API options
this.shadowRoot.registry.define('my-button', class extends Button {});
this.shadowRoot.registry.define('my-input', class extends Input {});
// ... etc.
```

If this were the case, we might even be able to recreate the bottom up upgrading missing in:

```html
<some-element>
   <template shadowroot="open" customregistry>
          <some-scoped-element>
                <template shadowroot="open" customregistry>
                        <other-scoped-element></other-scoped-element>
                </template>
          </some-scoped-element>
   </template>
</some-element>
```

Via JS, like:

```js
const someElement = document.querySelector('some-element');
const someScopedElement = someElement.shadowRoot.querySelector('some-scoped-element');
someScopedElement.shadowRoot.registry.define('other-scoped-element', class extends GenericElement {});
```

I feel like there's some security something about `ElementInternals` that this might be avoiding, so thanks for helping clear this up for me! 🙇🏼 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/914#issuecomment-1186646210

You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/914/1186646210@github.com>

Received on Monday, 18 July 2022 00:40:46 UTC