New issue
Advanced search Search tips

Issue 887181 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Feature



Sign in to add a comment

Custom Element with constructor that adds children can be added through script but not plain HTML.

Project Member Reported by rakina@chromium.org, Sep 20

Issue description

Adding a custom element that has children when constructed through script (setting innerHTML) works, but having the same element in HTML throws an error saying "Failed to construct 'CustomElement': The result must not have children" 

<script>
class TestElement extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = "upgraded";
  }
}
customElements.define("test-element", TestElement);
</script>

WORKS:
<div id="someDiv">
<div>
<script>
  someDiv.innerHTML = "<test-element></test-element>";
</script>

FAILS:
<test-element></test-element>
 
Components: -Blink>DOM Blink>HTML>CustomElements
Owner: ----
Status: Available (was: Assigned)
Labels: -Type-Bug Type-Feature
This is a behavior defined by the specification.  We have children check only for synchronous custom element creation.

However, this behavior is confusing, and we may show a console warning message for asynchronous custom element upgrade.

Sign in to add a comment