Skip to content

Commit 4a13b6c

Browse files
Jayson Chenchromium-wpt-export-bot
authored andcommitted
Fix parser registry lookup for declarative shadow root templates
The parser optimization in 2f14d02eaed47 changed the template check in HTMLConstructionSite::CreateElement from catching all template elements to only catching fragment-parsing templates or template content documents. This missed declarative shadow root templates, where SetOverrideInsertionTarget redirects output to the shadow root in the main document (so is_parsing_fragment_ is false and document.IsTemplateDocument() is false). As a result, elements inside declarative shadow root templates were getting the wrong registry from CurrentElement()->customElementRegistry() (which resolves via the template element's tree scope — the parent shadow root) instead of getting the registry from their actual target shadow root. Fix by distinguishing three cases when CurrentNode is a template: 1. Declarative shadow root template (IsShadowRootModeTemplate): use the target shadow root's own customElementRegistry(), which correctly returns null for scoped-waiting roots and the global registry for non-scoped roots. 2. Regular <template>: null the registry unconditionally, since template content documents have no browsing context. 3. Deeper descendants inside template content documents: null the registry (existing IsTemplateDocument check). Additionally, set ScopedCustomElementRegistryUsed() on the document when attaching a declarative shadow root with shadowrootcustomelementregistry, so that the per-element registry lookup path is activated during parsing. Add a test that an element's null customElementRegistry does not mutate after removal from a null-registry declarative shadow root. Bug: 490343466 Change-Id: I7878bfe187bea2cb6eb4f63d443685147a3c235b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7774289 Commit-Queue: Jayson Chen <jaysonchen@microsoft.com> Reviewed-by: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1620385}
1 parent 6489f94 commit 4a13b6c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<title>An element's null customElementRegistry should not mutate after removal</title>
3+
<meta name="author" title="Jayson Chen" href="mailto:jaysonchen@microsoft.com">
4+
<link rel="help" href="https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<body>
9+
<div id="host">
10+
<template shadowrootmode="open" shadowrootcustomelementregistry>
11+
<x-el></x-el>
12+
</template>
13+
</div>
14+
15+
<script>
16+
17+
test(() => {
18+
const sr = host.shadowRoot;
19+
const el = sr.querySelector('x-el');
20+
assert_equals(el.customElementRegistry, null,
21+
'customElementRegistry should be null while in null-registry shadow root');
22+
el.remove();
23+
assert_equals(el.customElementRegistry, null,
24+
'customElementRegistry should remain null after removal from null-registry shadow root');
25+
}, "An element's null customElementRegistry should not mutate after removal from a declarative shadow root with shadowrootcustomelementregistry.");
26+
</script>
27+
</body>

0 commit comments

Comments
 (0)