Skip to content

[WPT] Various test cases in custom-elements/registries/element-mutation.html fail#69430

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
rniwa:fix319388-scoped-custom-element-registries
Jul 15, 2026
Merged

[WPT] Various test cases in custom-elements/registries/element-mutation.html fail#69430
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
rniwa:fix319388-scoped-custom-element-registries

Conversation

@rniwa

@rniwa rniwa commented Jul 15, 2026

Copy link
Copy Markdown
Member

8b4bcb5

[WPT] Various test cases in custom-elements/registries/element-mutation.html fail
https://bugs.webkit.org/show_bug.cgi?id=319388

Reviewed by Chris Dumez.

The failure was caused by a built-in element (e.g. div) parsed inside an declarative
shadow root with null registry (e.g. declared with shadowrootcustomelementregistry
content attribute on template) not getting the usesNullCustomElementRegistry flag -
only custom elements and unknown elements did (in HTMLConstructionSite's
createHTMLElementOrFindCustomElementInterface inside the "if (!element)" block).
The built-in element merely resolved to null via its tree scope.

That worked for the original (parsed before any global registry was ensured), but
broke on cloning: once the global registry exists, cloning the subtree runs
Element::insertionSteps on the cloned nodes which pins the cloned element with
the global registry in the scoped map. Once pinned, registry.initialize(shadowRoot)
could no longer hand it the scoped registry - hence the failures.

This PR applies two fixes to address the failures.

1. HTMLConstructionSite.cpp - set usesNullCustomElementRegistry on all elements
   (built-in included) parsed inside a null-registry tree scope, so an element
   behaves identically to its clones and keeps resolving to null across mutations.
   This unifies the previously separate custom-element and fragment-parsing branches.
2. Element::attachShadow - an imperative attachShadow() with no explicit registry
   now always defaults to the document's registry, instead of null when the host
   carries the null-registry flag. The host stays null; only the new shadow root uses
   the global registry.

(2) is required because (1) gives built-in elements the flag, and without it their
attachShadow default would flip to null. As a bonus, it also fixes the pre-existing
ShadowRoot-init-declarative.html custom-element FAIL, which failed for this exact
reason.

Finally, this PR also addresses a bug that we weren't propagating the parent node's
null-registry-ness to a child node during non-fragment parsing by generalizing
the condition (no longer checks m_isParsingFragment).

Test: imported/w3c/web-platform-tests/custom-elements/registries/element-mutation.html

* LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/ShadowRoot-init-declarative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/element-mutation-expected.txt:
* Source/WebCore/dom/Element.cpp:
* Source/WebCore/html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):

Canonical link: https://commits.webkit.org/317215@main

054822f

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ⏳ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ⏳ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
⏳ 🛠 ios-safer-cpp ⏳ 🧪 mac-AS-debug-wk2 ❌ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 api-gtk
✅ 🛠 vision-sim ⏳ 🧪 mac-intel-wk2 ⏳ 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🧪 vision-wk2 ⏳ 🛠 mac-safer-cpp
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@rniwa rniwa requested a review from cdumez as a code owner July 15, 2026 00:41
@rniwa rniwa self-assigned this Jul 15, 2026
@rniwa rniwa added the New Bugs Unclassified bugs are placed in this component until the correct component can be determined. label Jul 15, 2026
@rniwa rniwa requested a review from annevk July 15, 2026 00:44
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 15, 2026

@cdumez cdumez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@rniwa

rniwa commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Not sure what's going on with GTK+'s editing/selection/drag-in-iframe.html.

@rniwa rniwa added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Jul 15, 2026
…on.html fail

https://bugs.webkit.org/show_bug.cgi?id=319388

Reviewed by Chris Dumez.

The failure was caused by a built-in element (e.g. div) parsed inside an declarative
shadow root with null registry (e.g. declared with shadowrootcustomelementregistry
content attribute on template) not getting the usesNullCustomElementRegistry flag -
only custom elements and unknown elements did (in HTMLConstructionSite's
createHTMLElementOrFindCustomElementInterface inside the "if (!element)" block).
The built-in element merely resolved to null via its tree scope.

That worked for the original (parsed before any global registry was ensured), but
broke on cloning: once the global registry exists, cloning the subtree runs
Element::insertionSteps on the cloned nodes which pins the cloned element with
the global registry in the scoped map. Once pinned, registry.initialize(shadowRoot)
could no longer hand it the scoped registry - hence the failures.

This PR applies two fixes to address the failures.

1. HTMLConstructionSite.cpp - set usesNullCustomElementRegistry on all elements
   (built-in included) parsed inside a null-registry tree scope, so an element
   behaves identically to its clones and keeps resolving to null across mutations.
   This unifies the previously separate custom-element and fragment-parsing branches.
2. Element::attachShadow - an imperative attachShadow() with no explicit registry
   now always defaults to the document's registry, instead of null when the host
   carries the null-registry flag. The host stays null; only the new shadow root uses
   the global registry.

(2) is required because (1) gives built-in elements the flag, and without it their
attachShadow default would flip to null. As a bonus, it also fixes the pre-existing
ShadowRoot-init-declarative.html custom-element FAIL, which failed for this exact
reason.

Finally, this PR also addresses a bug that we weren't propagating the parent node's
null-registry-ness to a child node during non-fragment parsing by generalizing
the condition (no longer checks m_isParsingFragment).

Test: imported/w3c/web-platform-tests/custom-elements/registries/element-mutation.html

* LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/ShadowRoot-init-declarative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/registries/element-mutation-expected.txt:
* Source/WebCore/dom/Element.cpp:
* Source/WebCore/html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):

Canonical link: https://commits.webkit.org/317215@main
@webkit-commit-queue webkit-commit-queue force-pushed the fix319388-scoped-custom-element-registries branch from 054822f to 8b4bcb5 Compare July 15, 2026 05:41
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 317215@main (8b4bcb5): https://commits.webkit.org/317215@main

Reviewed commits have been landed. Closing PR #69430 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 8b4bcb5 into WebKit:main Jul 15, 2026
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 15, 2026
@rniwa rniwa deleted the fix319388-scoped-custom-element-registries branch July 15, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Bugs Unclassified bugs are placed in this component until the correct component can be determined.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants