Skip to content

Should infinite recursion of custom element constructors be possible? #5118

@mfreed7

Description

@mfreed7

The custom element upgrade spec, section 4.13.5, step 1, says "If element is custom, then return". And there is a large example there showing a custom element constructor that attempts to call itself recursively. What should that example do?

A simplified example is:

customElements.define("x-foo", class extends HTMLElement {
  constructor() {
    super();
    customElements.upgrade(this);
  }
});

See this Chromium bug for a more detailed discussion of this situation. There is a debate about whether the constructor and/or CE reactions should happen in step 2 or step 4 of the CEReactions spec. If the constructor happens at step 2, and the (recursively triggered) upgrade reactions happen at step 4, then the current spec is correct, the Chromium implementation is wrong, and there should be no infinite recursion here. If, on the other hand, both the constructor and the (recursively triggered) upgrades happen within a single step (2 or 4) then the spec is wrong, Chromium is correct, and the example above will generate a JS stack overflow.

Metadata

Metadata

Assignees

Labels

topic: custom elementsRelates to custom elements (as defined in DOM and HTML)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions