Commit 4a13b6c
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
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments