- From: Xiaocheng Hu <notifications@github.com>
- Date: Tue, 06 Sep 2022 17:49:58 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/969@github.com>
This is a blocking issue of #716
Note: This issue is **not** about calling a custom element constructor directly
---
HTML element's [overridden constructor steps](https://html.spec.whatwg.org/#html-element-constructors) is called whenever we create a custom element. For example:
```javascript
class MyCustomElement extends HTMLElement {
constructor() {
super(); // Runs the overridden constructor steps
this.attachShadow(...);
...
}
}
customElements.define('my-custom', MyCustomElement);
```
The line `super()` is reached whenever we create a `my-custom` element, regardless of calling `createElement()`, setting `innerHTML` or calling the constructor directly.
The overridden constructor steps check the (unique) global `CustomElementRegistry` to find out if there's a custom element definition matching the currently called constructor, and throw an exception if there's none.
This gets trickier when there are multiple registries. For example, when we call `ShadowRoot.createElement()` and enter the `super()` call, we still need to know which registry we are using, but currently such information seems unavailable.
One very hacky idea:
- Whenever we are about to create a custom element with a given registry and definition, temporarily tag the constructor with the registry as an internal field `[[Registry]]`
- Then when we are inside `super()`, we can get the correct registry from `NewTarget`'s `[[Registry]]` field
- When the overridden constructor steps finish, clear the `[[Registry]]` field from `NewTarget`
@mfreed7 @justinfagnani @rniwa
--
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/969
You are receiving this because you are subscribed to this thread.
Message ID: <WICG/webcomponents/issues/969@github.com>
Received on Wednesday, 7 September 2022 00:50:10 UTC