Skip to content

Passing the scoped custom element registry to the fragment parser has non-obvious side effects #12274

@noamr

Description

@noamr

What is the issue with the HTML Standard?

Currently, the fragment parser uses the custom element registry of its context element when parsing.
(https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm step 8)

This has some observable side effects that might not be ideal.
Specifically, the custom element is upgraded and its constructor is invoked at fragment-parse time rather than at connection time.

It is observable in the following scenarios:

  • setting innerHTML on a disconnected element with a registry upgrades its custom elements and calls the constructors
  • When creating a contextual fragment, the elements are upgraded based on the context but the fragment might be added to a different element in the end
  • If there is any change in the registry between parsing time and connection time, the first one wins.
  • More acutely - see Custom element registry can call constructor of sanitizer-removed elements WICG/sanitizer-api#381. Elements are upgraded before the sanitizer gets to remove them.

Not sure how to go about this, since it's the only way those element-scoped registries are respected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agenda+To be discussed at a triage meetingtopic: 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