-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add declarative Shadow DOM features #858
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 <[email protected]> Auto-Submit: Mason Freed <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Cr-Commit-Position: refs/heads/master@{#760704}
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747
Ok, I believe this PR is ready for review. This is my first time with a PR of this size against DOM 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. |
Could you rebase it and force push so that the build output will (hopefully) be more useful? The other question I have is where we are at with respect to implementer interest. In particular @rniwa's last comment makes me think not all design issues have been resolved. |
Ok, I just force-pushed. Do I also need to fix the (pre-existing) issue with en-GB spelling of "serialisation", to get Travis to build?
As for implementer interest and @rniwa's last comment:
I believe this is exactly issue 871, to expose shadowRoot on element internals. I would like to take up that issue also, but separately, and it sounds like we're close to agreement on that thread.
This second point is exactly issue 809, to add a callback when parsing is "done". I also think we need to work on that issue, but again, separately. I'm in favor of a solution to that problem, and that is @rniwa's own issue, so presumably he agrees. Maybe it is my optimistic reading of the above, but it seemed like we might be close. I suppose we will need to wait for @rniwa to return to find out? In the meantime, what are Mozilla's thoughts on this API? One of your comments requested more clarity about the interaction between declarative and imperative shadow roots. Hopefully that's clear with this PR and the corresponding HTML PR? |
If you want to reference the HTML Standard's fragment serialization algorithm you want something like It might take some time for Mozilla to determine a position. I recommend filing an issue at https://github.com/mozilla/standards-positions. |
Thanks - done. I still don't quite understand the magic happening in the Makefile. I got that link from the HTML spec itself - go to https://html.spec.whatwg.org/#serialising-html-fragments and check out the fragment link there for "HTML fragment serialization algorithm".
Ok, thanks. I've filed an issue there. |
Well, the link was to a completely different domain, too. 😊 |
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528}
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528}
Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528}
Oh, ha! I didn't notice it was to w3. Yeah now I'm not sure where I got that link. 😬 |
…ng declarative Shadow DOM, a=testonly Automatic update from web-platform-tests Add ability to clone a template containing declarative Shadow DOM Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528} -- wpt-commits: 65659261a741bc42cfd35261430f47bd62deae4d wpt-pr: 23359
…ng declarative Shadow DOM, a=testonly Automatic update from web-platform-tests Add ability to clone a template containing declarative Shadow DOM Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528} -- wpt-commits: 65659261a741bc42cfd35261430f47bd62deae4d wpt-pr: 23359
…ng declarative Shadow DOM, a=testonly Automatic update from web-platform-tests Add ability to clone a template containing declarative Shadow DOM Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528} -- wpt-commits: 65659261a741bc42cfd35261430f47bd62deae4d wpt-pr: 23359
…ng declarative Shadow DOM, a=testonly Automatic update from web-platform-tests Add ability to clone a template containing declarative Shadow DOM Prior to this CL, this would not work correctly: <template id=target> <div> <template shadowroot=open>Content</template> </div> </template> <script> document.body.appendChild(target.content.cloneNode(true)); </script> The inner declarative Shadow DOM (<template shadowroot>) would not get cloned from the template content to the clone. With this CL, it now works correctly. Several tests were added to test nested template and declarative Shadow DOM nodes. This CL mirrors the DOM spec changes made in [1]. [1] whatwg/dom#858 Bug: 1042130 Change-Id: I05792e038dc694ac00d13531c657afaed754f747 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175062 Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Mason Freed <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#766528} -- wpt-commits: 65659261a741bc42cfd35261430f47bd62deae4d wpt-pr: 23359
Are there any comments on this PR, technically speaking? It is waiting for other implementer support, but it would be good to take care of any obvious spec-writing problems if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think that apart from formatting (and it needs rebasing), this largely looks fine. Cloning shadow trees looks rather odd to me though. The explainer also doesn't go into this from a quick scan.
dom.bs
Outdated
{{ShadowRootInit/delegatesFocus}}. | ||
<li><p>If <var>shadow host</var> has a non-null <a for=/>shadow root</a> whose | ||
<a for=ShadowRoot>is declarative shadow root</a> property is true, then <a for=/>remove</a> all of | ||
<a for=/>shadow root</a>'s <a>children</a>, in <a>tree order</a>. Return <var>shadow host</var>'s <a for=/>shadow root</a>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be clearer to have a single non-null step and then have these algorithm exists (throw and return) as substeps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Let me know if this is what you were expecting.
@@ -5872,6 +5896,10 @@ dictionary ShadowRootInit { | |||
required ShadowRootMode mode; | |||
boolean delegatesFocus = false; | |||
}; | |||
|
|||
dictionary GetInnerHTMLOptions { | |||
boolean includeShadowRoots = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the very least this should say OpenShadowRoots, but it seems better to me if we did not have a separate API here for open and closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the "rest" of this interface, as explained here in the explainer. In particular, the section just below that, Closed shadow roots goes into the details of the interface. You essentially get two knobs. includeShadowRoots
is an opt-in for any shadow roots to be serialized. The second input, closedRoots
is a list of closed shadow roots that you would like to be included. If a closed shadow root is encountered that is not in the list, it will be skipped to preserve encapsulation.
I am going to add the corresponding change to my HTML spec PR.
LMK if the above clarifies the situation, or if you have further questions.
Thanks for the review! I think i I addressed all of your comments, but let me know what else needs attention.
This is a good point, which wasn't previously in the explainer. I came across this behavior as I was implementing. Based on this comment, I've added a section to the explainer that details why this change was necessary - you can see that here. The TL/DR is that without this change (or something similar), you can't use declarative Shadow DOM inside an "ordinary" template. |
Just checking in on this PR. Is there anything missing, other than multi-implementer interest? |
Closing this, and replacing with PR 892. |
The explainer for this feature is here: https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md
The issue discussion is here: #831
There is a corresponding Pull Request for the HTML 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:
Preview | Diff