- From: Xiaocheng Hu <notifications@github.com>
- Date: Tue, 11 Apr 2023 12:58:54 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/914/1504012934@github.com>
The "winning proposal" has a (minor?) downside that we can't reuse registry for different shadow roots, even for the same component. So we need to create duplicate registries. For example: ```html <some-element> <template shadowrootmode="open" customregistry> <some-scoped-element></some-scoped-element> <some-other-scoped-element></some-other-scoped-element> </template> </some-element> <script type="module"> class SomeElement extends HTMLElement { constructor() { super(); if (this.shadowRoot) { // This is duplicated on every instance of SomeElement this.shadowRoot.registry.define('some-scoped-element', SomeScopedElement); this.shadowRoot.registry.define('some-other-scoped-element', SomeOtherScopedElement); } else { ... } } } customElements.define('some-element', SomeElement); </script> ``` Not sure how big of an issue it is, since declarative shadow DOM already needs to duplicate the markup and other things. But we can still avoid this by allowing setting `ShadowRoot.registry` if the `ShadowRoot` currently has a non-null but empty registry: ```html <some-element> <template shadowrootmode="open" customregistry> <some-scoped-element></some-scoped-element> <some-other-scoped-element></some-other-scoped-element> </template> </some-element> <script type="module"> import { registry } from './some-element-registry.mjs'; class SomeElement extends HTMLElement { constructor() { super(); if (this.shadowRoot) { // This makes all SomeElement instances share the same registry this.shadowRoot.registry = registry; } else { ... } } } customElements.define('some-element', SomeElement); </script> ``` I think it has been debated many times at various places whether we should allow setting `ShadowRoot.registry`, and the general consensus is no, as changing definitions with already upgraded elements can be quite problematic. But if the scoped registry is empty, then I don't see any issue -- it's the same as duplicating the definitions from the other registry. So I don't really see any downside from this proposal, and it's a free performance gain. -- Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/914#issuecomment-1504012934 You are receiving this because you are subscribed to this thread. Message ID: <WICG/webcomponents/issues/914/1504012934@github.com>
Received on Tuesday, 11 April 2023 19:59:00 UTC