Skip to content

Restore active custom element constructor map entries after construction#1494

Merged
annevk merged 1 commit into
whatwg:mainfrom
annevk:active-custom-element-constructor-map-restore
Jul 17, 2026
Merged

Restore active custom element constructor map entries after construction#1494
annevk merged 1 commit into
whatwg:mainfrom
annevk:active-custom-element-constructor-map-restore

Conversation

@annevk

@annevk annevk commented Jul 17, 2026

Copy link
Copy Markdown
Member

Create an element sets the active custom element constructor map entry for the constructor it is about to construct, then removed it once construction finished. A re-entrant construction of the same constructor for a different registry therefore clobbered the outer entry, and its removal left the outer construction to resolve against the wrong registry.

Save the previous entry before setting it and restore it afterwards, so the outer registry survives a re-entrant construction. This mirrors the same change to the HTML element constructor and upgrade an element.

See whatwg/html#12696.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

Create an element sets the active custom element constructor map entry
for the constructor it is about to construct, then removed it once
construction finished. A re-entrant construction of the same constructor
for a different registry therefore clobbered the outer entry, and its
removal left the outer construction to resolve against the wrong
registry.

Save the previous entry before setting it and restore it afterwards, so
the outer registry survives a re-entrant construction. This mirrors the
same change to the HTML element constructor and upgrade an element.

See whatwg/html#12696.

@keithamus keithamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Comment thread dom.bs
Comment on lines +7067 to +7073
<li><p>If <var>previousRegistry</var> is null, then <a for=map>remove</a> the
<a>surrounding agent</a>'s
<a for="similar-origin window agent">active custom element constructor map</a>[<var>C</var>].

<p class=note>Under normal circumstances it will already have been removed at this point.
<li><p>Otherwise, <a for=map>set</a> the <a>surrounding agent</a>'s
<a for="similar-origin window agent">active custom element constructor map</a>[<var>C</var>] to
<var>previousRegistry</var>.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTML spec has these two steps combined, but DOM has them as 2 discrete steps. Any particular reason why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oversight; I've now made it two steps in HTML as well.

annevk added a commit to whatwg/html that referenced this pull request Jul 17, 2026
The active custom element constructor map is keyed by constructor, so a
re-entrant upgrade of the same constructor for a different registry
overwrote the outer upgrade's entry. Because the entry was then removed
(on read in the HTML element constructor, and unconditionally when the
upgrade finished), the outer super() call lost its registry and resolved
against the wrong one.

Save the previous entry before setting it and restore it afterwards, and
stop removing it when read, so that the outer registry survives a
re-entrant upgrade.

DOM PR: whatwg/dom#1494

Tests: web-platform-tests/wpt#61364

Fixes #12691.
@annevk
annevk merged commit 84ec22b into whatwg:main Jul 17, 2026
2 checks passed
@annevk
annevk deleted the active-custom-element-constructor-map-restore branch July 17, 2026 11:42
annevk added a commit to annevk/WebKit that referenced this pull request Jul 18, 2026
https://bugs.webkit.org/show_bug.cgi?id=319658

Reviewed by NOBODY (OOPS!).

Keith Cirkel pointed out that the constructor map as defined did not
quite work and also that WebKit did not implement it.

This aligns WebKit with the proposed changes to DOM and HTML and also
adds some additional test coverage for the gaps:

- whatwg/dom#1494
- whatwg/html#12696

Tests: imported/w3c/web-platform-tests/custom-elements/createElement-reentrant-construction.window.html
       imported/w3c/web-platform-tests/custom-elements/registries/constructor-direct-call-fallback-registry.window.html
       imported/w3c/web-platform-tests/custom-elements/registries/constructor-reentry-createElement.window.html
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request Jul 18, 2026
https://bugs.webkit.org/show_bug.cgi?id=319658

Reviewed by Ryosuke Niwa.

Keith Cirkel pointed out that the constructor map as defined did not
quite work and also that WebKit did not implement it.

This aligns WebKit with the proposed changes to DOM and HTML and also
adds some additional test coverage for the gaps:

- whatwg/dom#1494
- whatwg/html#12696

Tests: imported/w3c/web-platform-tests/custom-elements/createElement-reentrant-construction.window.html
       imported/w3c/web-platform-tests/custom-elements/registries/constructor-direct-call-fallback-registry.window.html
       imported/w3c/web-platform-tests/custom-elements/registries/constructor-reentry-createElement.window.html

Canonical link: https://commits.webkit.org/317462@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants