From ffe797e3646dfa9a24151ff454a61fa56f5a4ca2 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Thu, 18 Jan 2024 20:30:02 -0800 Subject: [PATCH] Disallow multiple declarative roots and mismatched imperative ones Two changes: 1. If two declarative shadow roots are included within a single host element, only the *first* one will remain. This is a change in behavior from before, but reached consensus [1] and hopefully won't be a breaking change for anyone. 2. If attachShadow() is used on an existing declarative shadow root, and the parameters (e.g. shadow root type, etc.) do not match, an exception is thrown. This, also, is a breaking change, but hopefully not one that gets hit. See also [1]. See [2] and [3] for the corresponding spec PRs. [1] https://github.com/whatwg/dom/issues/1235 [2] https://github.com/whatwg/html/pull/10069 [3] https://github.com/whatwg/dom/pull/1246 Bug: 1379513,1042130 Change-Id: Ia81088227797013f9f62f5ac90f76898663b0bc4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5191750 Commit-Queue: Mason Freed Auto-Submit: Mason Freed Commit-Queue: David Baron Reviewed-by: David Baron Cr-Commit-Position: refs/heads/main@{#1249214} --- .../declarative-shadow-dom-attachment.html | 8 +- .../declarative-shadow-dom-basic.html | 8 +- .../declarative-shadow-dom-repeats.html | 73 +++++++++++++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 shadow-dom/declarative/declarative-shadow-dom-repeats.html diff --git a/shadow-dom/declarative/declarative-shadow-dom-attachment.html b/shadow-dom/declarative/declarative-shadow-dom-attachment.html index 6fb2a8a5ecc30f5..aec9a276f931f01 100644 --- a/shadow-dom/declarative/declarative-shadow-dom-attachment.html +++ b/shadow-dom/declarative/declarative-shadow-dom-attachment.html @@ -42,9 +42,13 @@ originalShadowRoot = element.shadowRoot; } - // Now, call attachShadow() and make sure we get back the same (original) shadowRoot, but empty. const oppositeMode = (mode === 'open') ? 'closed' : 'open'; - const newShadow = element.attachShadow({mode: oppositeMode}); // Should be no exception here + assert_throws_dom('NotSupportedError', () => { + element.attachShadow({mode: oppositeMode}); + }, 'Calling attachShadow with a declarative shadow fails if the mode doesn\'t match'); + + // Now, call attachShadow() and make sure we get back the same (original) shadowRoot, but empty. + const newShadow = element.attachShadow({mode: mode, delegatesFocus: delegatesFocus}); if (mode === 'open') { assert_equals(element.shadowRoot, originalShadowRoot, 'The same shadow root should be returned'); assert_equals(element.shadowRoot.innerHTML, '', 'Empty shadow content'); diff --git a/shadow-dom/declarative/declarative-shadow-dom-basic.html b/shadow-dom/declarative/declarative-shadow-dom-basic.html index 20ca34f6f3e2594..8799978804a53b4 100644 --- a/shadow-dom/declarative/declarative-shadow-dom-basic.html +++ b/shadow-dom/declarative/declarative-shadow-dom-basic.html @@ -154,10 +154,14 @@ diff --git a/shadow-dom/declarative/declarative-shadow-dom-repeats.html b/shadow-dom/declarative/declarative-shadow-dom-repeats.html new file mode 100644 index 000000000000000..3da9cff360c64d7 --- /dev/null +++ b/shadow-dom/declarative/declarative-shadow-dom-repeats.html @@ -0,0 +1,73 @@ + +Declarative Shadow DOM Element Attachment + + + + + + + + + + +
+ + +
+ +
+ + +
+ + + +
+ +
+ + + +
+ +
+ +