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.
This commit is contained in:
Sam Atkins 2025-11-25 16:06:44 +00:00 committed by Jelle Raaijmakers
parent 8ca4833885
commit aac387bcc6
Notes: github-actions[bot] 2025-11-26 08:53:57 +00:00
3 changed files with 12 additions and 9 deletions

View file

@ -4511,6 +4511,11 @@ GC::Ref<DOM::Document> Document::appropriate_template_contents_owner_document()
if (document_type() == Type::HTML) if (document_type() == Type::HTML)
new_document->set_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. // 3. Set doc's associated inert template document to new doc.
m_associated_inert_template_document = new_document; m_associated_inert_template_document = new_document;
} }

View file

@ -2,7 +2,6 @@ Harness status: OK
Found 2 tests Found 2 tests
1 Pass 2 Pass
1 Fail
Pass can use ShadowRoot as options for attachShadow Pass can use ShadowRoot as options for attachShadow
Fail can use ShadowRoot in document fragment as options for attachShadow Pass can use ShadowRoot in document fragment as options for attachShadow

View file

@ -2,8 +2,7 @@ Harness status: OK
Found 22 tests Found 22 tests
18 Pass 22 Pass
4 Fail
Pass Declarative Shadow DOM: Basic test Pass Declarative Shadow DOM: Basic test
Pass Declarative Shadow DOM: Feature detection Pass Declarative Shadow DOM: Feature detection
Pass Shadowrootmode reflection 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: delegates focus attribute
Pass Declarative Shadow DOM: clonable attribute Pass Declarative Shadow DOM: clonable attribute
Pass Declarative Shadow DOM: Multiple roots Pass Declarative Shadow DOM: Multiple roots
Fail Declarative Shadow DOM: template containing declarative shadow root (with shadowrootclonable) Pass Declarative Shadow DOM: template containing declarative shadow root (with shadowrootclonable)
Fail Declarative Shadow DOM: template containing (deeply nested) declarative shadow root Pass Declarative Shadow DOM: template containing (deeply nested) declarative shadow root
Fail Declarative Shadow DOM: template containing a template containing declarative shadow root Pass 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 and UA shadow root
Pass Declarative Shadow DOM: template containing closed 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: declarative shadow roots are not supported by the template element
Pass Declarative Shadow DOM: explicit test that exceptions are not thrown Pass Declarative Shadow DOM: explicit test that exceptions are not thrown