From aac387bcc649fb8d44f1dd58d15239a2e95a053a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 25 Nov 2025 16:06:44 +0000 Subject: [PATCH] LibWeb/DOM: Copy "allow declarative shadow roots" to template document This flag defaults to false for new Documents, such as the one created here for use by template elements' contents. Without setting it to true, nothing inside a template can have a declarative shadow dom. As noted, this appears to be a spec issue. I am not convinced that this is the correct fix, but it is simple and does solve the issue without any apparent regressions. --- Libraries/LibWeb/DOM/Document.cpp | 5 +++++ .../shadow-dom/attachShadow-with-ShadowRoot.txt | 5 ++--- .../declarative/declarative-shadow-dom-basic.txt | 11 +++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index b4c61fb3491..7e4d61d3182 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -4511,6 +4511,11 @@ GC::Ref Document::appropriate_template_contents_owner_document() if (document_type() == Type::HTML) new_document->set_document_type(Type::HTML); + // AD-HOC: Copy over the "allow declarative shadow roots" flag, otherwise no elements inside templates will + // be able to have declarative shadow roots. + // Spec issue: https://github.com/whatwg/html/issues/11955 + new_document->set_allow_declarative_shadow_roots(allow_declarative_shadow_roots()); + // 3. Set doc's associated inert template document to new doc. m_associated_inert_template_document = new_document; } diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/attachShadow-with-ShadowRoot.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/attachShadow-with-ShadowRoot.txt index 5fdd2350d47..2c70fb40664 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/attachShadow-with-ShadowRoot.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/attachShadow-with-ShadowRoot.txt @@ -2,7 +2,6 @@ Harness status: OK Found 2 tests -1 Pass -1 Fail +2 Pass Pass can use ShadowRoot as options for attachShadow -Fail can use ShadowRoot in document fragment as options for attachShadow \ No newline at end of file +Pass can use ShadowRoot in document fragment as options for attachShadow \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/declarative/declarative-shadow-dom-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/declarative/declarative-shadow-dom-basic.txt index d543fdf7b50..bb970d7b1bc 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/declarative/declarative-shadow-dom-basic.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/declarative/declarative-shadow-dom-basic.txt @@ -2,8 +2,7 @@ Harness status: OK Found 22 tests -18 Pass -4 Fail +22 Pass Pass Declarative Shadow DOM: Basic test Pass Declarative Shadow DOM: Feature detection Pass Shadowrootmode reflection @@ -19,10 +18,10 @@ Pass Declarative Shadow DOM: Missing closing tag Pass Declarative Shadow DOM: delegates focus attribute Pass Declarative Shadow DOM: clonable attribute Pass Declarative Shadow DOM: Multiple roots -Fail Declarative Shadow DOM: template containing declarative shadow root (with shadowrootclonable) -Fail Declarative Shadow DOM: template containing (deeply nested) declarative shadow root -Fail Declarative Shadow DOM: template containing a template containing declarative shadow root -Fail Declarative Shadow DOM: template containing declarative shadow root and UA shadow root +Pass Declarative Shadow DOM: template containing declarative shadow root (with shadowrootclonable) +Pass Declarative Shadow DOM: template containing (deeply nested) declarative shadow root +Pass Declarative Shadow DOM: template containing a template containing declarative shadow root +Pass Declarative Shadow DOM: template containing declarative shadow root and UA shadow root Pass Declarative Shadow DOM: template containing closed declarative shadow root and UA shadow root Pass Declarative Shadow DOM: declarative shadow roots are not supported by the template element Pass Declarative Shadow DOM: explicit test that exceptions are not thrown \ No newline at end of file