Skip to content

Add declarative Shadow DOM features#5465

Merged
annevk merged 14 commits intowhatwg:mainfrom
mfreed7:add_declarative
Oct 29, 2023
Merged

Add declarative Shadow DOM features#5465
annevk merged 14 commits intowhatwg:mainfrom
mfreed7:add_declarative

Conversation

@mfreed7
Copy link
Collaborator

@mfreed7 mfreed7 commented Apr 17, 2020

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.

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 )

@sideshowbarker sideshowbarker added the impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation label Apr 18, 2020
@annevk annevk added needs implementer interest Moving the issue forward requires implementers to express interest topic: shadow Relates to shadow trees (as defined in DOM) labels Apr 20, 2020
pull bot pushed a commit to Yannic/chromium that referenced this pull request Apr 21, 2020
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}
@mfreed7
Copy link
Collaborator Author

mfreed7 commented May 4, 2020

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.

@mfreed7
Copy link
Collaborator Author

mfreed7 commented May 21, 2020

Any comments on this PR? No rush, just bumping it in case people would like to take a look.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Jun 11, 2020

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 closed shadow roots to the serialization algorithm, which is used by my latest code in the DOM PR.

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Aug 4, 2020

Just checking in on this PR. Is there anything missing, other than multi-implementer interest?

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 4, 2020
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
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 5, 2020
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
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 5, 2020
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
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 5, 2020
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}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 5, 2020
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}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Nov 7, 2020
…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
sidvishnoi pushed a commit to sidvishnoi/gecko-webmonetization that referenced this pull request Nov 10, 2020
…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
@mfreed7
Copy link
Collaborator Author

mfreed7 commented Nov 24, 2020

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 <span>include shadow roots flag<span> which does not contain a <p>. Help.

mfreed7 and others added 12 commits October 11, 2023 09:09
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
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 11, 2023
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
@mfreed7
Copy link
Collaborator Author

mfreed7 commented Oct 11, 2023

This now needs rebasing on top of 3ca0811 and make the appropriate changes to those algorithms. I can take care of a final nit commit after that and then after you double check we can hopefully finally land this.

Sounds good, will do.

Done. Let me know if the new text looks ok.

I'll take care of this today, in anticipation of this PR landing.

web-platform-tests/wpt#42488

aarongable pushed a commit to chromium/chromium that referenced this pull request Oct 11, 2023
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}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 12, 2023
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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the tests the tests don't match the specification here. I think the specification is better, but it might not be worth the churn.

@rniwa @mfreed7?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, did you have a chance to review the commit I already pushed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test update has landed. At this point the tests should match this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Oct 29, 2023

🎉 Thanks for all of the reviews to get this landed!

@annevk
Copy link
Member

annevk commented Oct 30, 2023

@mfreed7 thank you! For contributing this feature to the web and working on these PRs over a period of three(!) years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation topic: shadow Relates to shadow trees (as defined in DOM)

Development

Successfully merging this pull request may close these issues.

Allow speculative fetches in Declarative Shadow DOM template elements

10 participants