Add declarative Shadow DOM features#5465
Conversation
This CL cleans up the variations of element::attachShadow(), refactoring the common subset back into attachShadow(). It also replaces the bool delegates_focus and manual_slotting parameters with enum versions that are common across declarative and imperative calls. This CL should not change any functionality. The spec text comes from my two PRs against DOM [1] and HTML [2]. [1] whatwg/dom#858 [2] whatwg/html#5465 Bug: 1042130 Change-Id: I3835b9d344d8005b6854909f287083cd984e832e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155144 Commit-Queue: Mason Freed <masonfreed@chromium.org> Auto-Submit: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/master@{#760704}
|
Ok, I believe this PR is ready for review. This is my first time with a PR of this size against HTML so please let me know what I need to change. All of this PR has now been implemented in Chromium behind the DeclarativeShadowDOM flag, and WPT tests have been written. |
|
Any comments on this PR? No rush, just bumping it in case people would like to take a look. |
annevk
left a comment
There was a problem hiding this comment.
It seems this doesn't properly introduce all the new template attributes and adds them to the various indexes (top of the source document has instructions). I guess some special care is needed given they seem to be parser-only.
Thanks for the review! I believe I've addressed all of your comments, but let me know if I missed anything. Note that the latest push also includes the addition of |
|
Just checking in on this PR. Is there anything missing, other than multi-implementer interest? |
f3c293e to
29cdf7e
Compare
4e2da5b to
57f9319
Compare
This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc
This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc
This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc
This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513525 Commit-Queue: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Cr-Commit-Position: refs/heads/master@{#824591}
This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513525 Commit-Queue: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Cr-Commit-Position: refs/heads/master@{#824591}
…arsing to be opt-in, a=testonly Automatic update from web-platform-tests Change declarative Shadow DOM fragment parsing to be opt-in This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513525 Commit-Queue: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Cr-Commit-Position: refs/heads/master@{#824591} -- wpt-commits: b13461b9a46b46eb1b092a58bde2b10418e7a73d wpt-pr: 26398
…arsing to be opt-in, a=testonly Automatic update from web-platform-tests Change declarative Shadow DOM fragment parsing to be opt-in This CL implements most of the suggestions from [1], which effectively block declarative Shadow DOM from being used by any fragment parser entry point, unless an explicit opt-in is toggled. The opt-ins include: - DOMParser.allowDeclarativeShadowDom = true; - HTMLTemplateElement.allowDeclarativeShadowDom = true; - XMLHttpRequest.allowDeclarativeShadowDom = true; - DocumentFragment.allowDeclarativeShadowDom = true; - Document.allowDeclarativeShadowDom = true; // For innerHTML - A new <iframe> sandbox flag: allow-declarative-shadow-dom This mitigates the potential client-side XSS sanitizer bypass detailed in the explainer and at [1]. Assuming these changes are functional, and mitigate the issue, this new behavior will be folded into the spec PRs at [2] and [3]. But given the security implications of the existing code, I'd like to get this landed first. [1] whatwg/dom#912 (comment) [2] whatwg/html#5465 [3] whatwg/dom#892 Bug: 1042130 Change-Id: I088f28f63078a0d26e354a4442494c0132b47ffc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513525 Commit-Queue: Mason Freed <masonfreed@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Cr-Commit-Position: refs/heads/master@{#824591} -- wpt-commits: b13461b9a46b46eb1b092a58bde2b10418e7a73d wpt-pr: 26398
96267bf to
53dde66
Compare
|
This PR has been updated to include the "opt-in" mechanics described in #912. The changes I made here roughly match the current implementation of Chromium, so I'm hoping they're functional. But comments appreciated. Note that no matter what I do, I am unable to get rid of the "parse error while closing p element" error. I bisected this error down to the addition of |
53dde66 to
0067e75
Compare
More edits Fixup Cleanup Add language for content Add shadow root serialization Link to new "attach a shadow root" algorithm. Added exception handling. Add early-out for topmost node Added shadowroot to HTMLTemplateElement for feature detection Addressed annevk's comments Add available_to_internals = true Add declarative shadow dom opt-in mechanics Trying, unsuccessfully, to get rid of "parse error while closing p element" Remove data-x for instance checks Merge fixup Rename include shadow roots state Strip out serialization stuff Lint cleanup Fix closing tags Fix dfn Fix conformance error Address all comments Fix lint First cut at streaming DSD definition Address some comments Address @rniwa comments Capitalization Rename shadowrootmode and add clonable Address comments Address comments Line length Fix regular document parsing Address comments Update to match DOM's new `declarative` Clean up call to attach a shadow root Address speculative parser comment Replace tri-state with boolean Allow about:blank Address annevk comments Address annevk comments Report the exception
8686d64 to
d65e189
Compare
The spec PR [1] is about to land, so these tests should no longer be tentative. [1] whatwg/html#5465 Bug: 1379513 Change-Id: I577abb26b3c29a04f14ddafec7400abadb4119ed
Done. Let me know if the new text looks ok.
|
The spec PR [1] is about to land, so these tests should no longer be tentative. [1] whatwg/html#5465 Bug: 1379513 Change-Id: I577abb26b3c29a04f14ddafec7400abadb4119ed Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4932173 Auto-Submit: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Reviewed-by: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1208576}
The spec PR [1] is about to land, so these tests should no longer be tentative. [1] whatwg/html#5465 Bug: 1379513 Change-Id: I577abb26b3c29a04f14ddafec7400abadb4119ed Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4932173 Auto-Submit: Mason Freed <masonf@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Reviewed-by: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1208576}
| [<span>HTMLConstructor</span>] constructor(); | ||
|
|
||
| readonly attribute <span>DocumentFragment</span> <span data-x="dom-template-content">content</span>; | ||
| [<span>CEReactions</span>] attribute DOMString <span data-x="dom-template-shadowrootmode">shadowRootMode</span>; |
There was a problem hiding this comment.
Both Chromium and WebKit fail this assert:
document.createElement("template").shadowRootMode === ""
is this tested and planned to be fixed or should we change the standard?
There was a problem hiding this comment.
Both Chromium and WebKit fail this assert:
document.createElement("template").shadowRootMode === ""is this tested and planned to be fixed or should we change the standard?
This is likely due to your request to change from nullable? It'll require a change to browsers, which hasn't happened yet. I'd obviously be happier not changing browsers and instead changing the standard.
There was a problem hiding this comment.
I was expecting tests and such to be updated as we reached agreement on things here. Are there other things that might now be out-of-sync?
There was a problem hiding this comment.
I was expecting tests and such to be updated as we reached agreement on things here. Are there other things that might now be out-of-sync?
That'll require a (breaking) behavior change in Chrome, so no, I wasn't planning to do that work until I was sure this behavior "stuck". I.e. when this PR lands.
I don't believe there were other breaking changes you requested, no. I believe this is the only one.
There was a problem hiding this comment.
I'm a bit puzzled by these comments. In the initial PR there wasn't even a shadowrootmode attribute. It looks like it was called shadowroot. I think we made a number of "breaking" changes over the lifetime of this PR. I'm happy to push a commit that makes this attribute return null, but I'd really like to be sure it's the only thing where the specification mismatches with the tests and implementations.
There was a problem hiding this comment.
Also, did you have a chance to review the commit I already pushed?
There was a problem hiding this comment.
I'm a bit puzzled by these comments. In the initial PR there wasn't even a
shadowrootmodeattribute. It looks like it was calledshadowroot. I think we made a number of "breaking" changes over the lifetime of this PR.
Sorry you're puzzled. The "initial PR" was 3.5 years ago, and a lot has happened in the intervening years. I've shipped and then deprecated the original shadowroot attribute in Chromium. As discussion resumed on the PR in 2023, we renamed to shadowrootmode and added the corresponding IDL. I had to push through some (reasonable) opposition to bikeshedding after shipping. I then shipped again, with shadowrootmode, so that developers had something to migrate to from the old shadowroot. Five weeks ago, you requested the change from DOMString? to DOMString for shadowRootMode and I agreed, to try to finally get this PR landed. You then asked (just above) whether this was "worth the churn". In general, through all of this, I'd say "no it has never been worth the churn". But I'd like to get this feature shipped interoperably, so as with the other changes, I went along with this one, and I'm ok keeping it as DOMString. Hopefully it's the last change, and we can finally land this PR.
I'm happy to push a commit that makes this attribute return null, but I'd really like to be sure it's the only thing where the specification mismatches with the tests and implementations.
I believe this is the only thing that doesn't match, and in an hour or two, the test update should land. At that point, the spec should match the tests. Once this PR lands, I'll make the behavior change to Chromium (for DOMString? -> DOMString), so it'll at least match one implementation. I can't speak for other implementations.
Also, did you have a chance to review the commit I already pushed?
I just reviewed the nits commit, and all of those changes look good to me. Thanks.
There was a problem hiding this comment.
The test update has landed. At this point the tests should match this PR.
There was a problem hiding this comment.
Thanks for the update, that helps. I'm happy to make the shadowRootMode change in WebKit so let's go with that given you already updated the tests.
I created web-platform-tests/wpt#42833 to reflect that getInnerHTML() is non-standard and also took the opportunity to add some shadowRootMode setter coverage.
|
🎉 Thanks for all of the reviews to get this landed! |
|
@mfreed7 thank you! For contributing this feature to the web and working on these PRs over a period of three(!) years. |
The explainer for this feature is here: https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md
The issue discussion is here: whatwg/dom#831
There is a corresponding Pull Request for the DOM spec that goes along with this PR.
At least two implementers are interested (and none opposed):
Tests are written and can be reviewed and commented upon at:
Implementation bugs are filed:
Closes #7069
/acknowledgements.html ( diff )
/document-lifecycle.html ( diff )
/document-sequences.html ( diff )
/dynamic-markup-insertion.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/parsing.html ( diff )
/scripting.html ( diff )