Automatic update from web-platform-tests
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}
--
wpt-commits: 4a13b6cb08efdb0bfeabf32559d981b550fb4dfc
wpt-pr: 59459
28 lines
1.1 KiB
HTML
28 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<title>An element's null customElementRegistry should not mutate after removal</title>
|
|
<meta name="author" title="Jayson Chen" href="mailto:jaysonchen@microsoft.com">
|
|
<link rel="help" href="https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
|
|
<body>
|
|
<div id="host">
|
|
<template shadowrootmode="open" shadowrootcustomelementregistry>
|
|
<x-el></x-el>
|
|
</template>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
test(() => {
|
|
const sr = host.shadowRoot;
|
|
const el = sr.querySelector('x-el');
|
|
assert_equals(el.customElementRegistry, null,
|
|
'customElementRegistry should be null while in null-registry shadow root');
|
|
el.remove();
|
|
assert_equals(el.customElementRegistry, null,
|
|
'customElementRegistry should remain null after removal from null-registry shadow root');
|
|
}, "An element's null customElementRegistry should not mutate after removal from a declarative shadow root with shadowrootcustomelementregistry.");
|
|
</script>
|
|
</body>
|