-
Notifications
You must be signed in to change notification settings - Fork 295
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 Imperative Slot API #860
Conversation
Thanks for your review. I updated the corresponding HTML spec to include the concept of manuallyAssignedNodes and used that concept within [find a slot]. In addition, I removed a number of steps under [find a slot][step 5] where slotAssignment == 'manual'. I found those steps complicates things and unnecessary. Hopefully, the new revision is more clear. I didn't want my local branch to be too far out of date, so I fetched from whatwg:master and rebased my changes on top. It changed history so now your previous reviews aren't matched. Maybe I should have done a merge instead? Sorry for any inconvenience. Thanks again for your review. |
Thanks for reviewing. I've uploaded a new revision for review. |
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 this looks good now, modulo a couple minor nits.
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
I don't really understand the setup anymore. I thought manually assigned nodes was mutually exclusive with assigned nodes, but here the assign slottables algorithm can end up setting both. |
annevk@ I removed the additional step in assign slottables. I also sent you an email for some clarification based on your comments in the corresponding HTML spec. Thanks. |
FWIW, what's being proposed here seems fine. |
dom.bs
Outdated
@@ -2195,6 +2195,10 @@ steps:</p> | |||
<li><p>If the <i>open flag</i> is set and <var>shadow</var>'s <a for=ShadowRoot>mode</a> is | |||
<em>not</em> "<code>open</code>", then return null.</p></li> | |||
|
|||
<li><p>If <var>shadow</var>'s <a for=ShadowRoot>slot assignment</a> is set to "<code>manual</code>", | |||
return the <a>slot</a> in <var>shadow</var>'s <a for=tree>descendants</a> whose <a>manually assigned nodes</a> | |||
includes <var>slottable</var>, if any, and null otherwise.</p></li> |
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.
you want <a for=set>contains</a>
instead of includes here I think. It's a set right?
And I guess we're not bothering with tree order and such since there can only be one such slot.
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.
Thanks. Yes, contains is correct. I see how the verbiage is being used.
Right, there's can only be one slot because the corresponding HTML spec for HTMLSlotElement::assign() ensures that.
@@ -2450,7 +2454,8 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run | |||
<li><p>Otherwise, <a for=set>insert</a> <var>node</var> into <var>parent</var>'s | |||
<a for=tree>children</a> before <var>child</var>'s <a for=tree>index</a>. | |||
|
|||
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> and <var>node</var> is a | |||
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> with its <a for=tree>root</a>'s | |||
<a for=ShadowRoot>slot assignment</a> set to "<code>auto</code>" and <var>node</var> is a | |||
<a>slottable</a>, then <a>assign a slot</a> for <var>node</var>. | |||
|
|||
<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a>, and |
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.
Why should this step not be skipped?
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.
This step,
** If parent’s root is a shadow root, and parent is a slot whose assigned nodes is the empty list, then run signal a slot change for parent. **
is to signal slot change event because the slot's fallback content has changed.
For slot assignment "manual", the slot still supports fallback content.
<a for=tree>root</a>'s <a for=ShadowRoot>slot assignment</a> set to "<code>auto</code>", | ||
then <a for=set>remove</a> <var>node</var> from its <a>assigned slot</a>'s <a>manually assigned nodes</a>. | ||
|
||
<li><p>Run <a>assign slottables</a> for <var>node</var>'s <a>assigned slot</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.
Here too I have the feeling we're not skipping enough for the manual case. Same below.
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'm not sure how much optimization can be done here. Once the assigned node has been removed from slot's manually assigned node, we need to recalculate the slot's assigned nodes and signal slot change event. Both occurs inside assign slottables.
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 guess that's fair.
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.
How can this be right? assign slottables would set the list of assigned nodes to slottable matching the slot in tree order. It would mean that we're always re-order slottable in the tree order regardless of in what order they're inserted.
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.
Thanks for catching that. I've updated the find-slottables algorithm to preserve the order of manually assigned nodes.
@yuzhe-han would you mind responding to @annevk's comments? It'd be good to get this merged; I understand Chrome has shipped this. |
I've update the spec. Please review. Thanks. |
<a for=tree>root</a>'s <a for=ShadowRoot>slot assignment</a> set to "<code>auto</code>", | ||
then <a for=set>remove</a> <var>node</var> from its <a>assigned slot</a>'s <a>manually assigned nodes</a>. | ||
|
||
<li><p>Run <a>assign slottables</a> for <var>node</var>'s <a>assigned slot</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 guess that's fair.
And yeah, if manually assigned slots is the only error that will be resolved once the HTML PR merges. Note that you also need to make your membership of the googlers organization public for the Participation check. |
<li><p>for each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</a>, | ||
if <var>slot</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a> whose <a for=tree>root</a>'s | ||
<a for=ShadowRoot>slot assignment</a> is "<code>manual</code>", then set <var>slot</var>'s | ||
<a>manually assigned nodes</a> to an empty set. |
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.
Hm... this would be different from what we've been discussing in AOM:
whatwg/html#4925
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.
How does this relate to that?
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.
Well, it would mean that that this slot.assingedNodes would behave differently from element ID reflection, which seems bad.
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.
Removed.
… proposal [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it.
… proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it.
…om `auto` to match the latest proposal, a=testonly Automatic update from web-platform-tests Update `SlotAssignmentMode` to `name` from `auto` to match the latest proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it. -- wpt-commits: 875f4c73ec1122cd0ea05580f6b56fda0ef71cc7 wpt-pr: 27256
…om `auto` to match the latest proposal, a=testonly Automatic update from web-platform-tests Update `SlotAssignmentMode` to `name` from `auto` to match the latest proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it. -- wpt-commits: 875f4c73ec1122cd0ea05580f6b56fda0ef71cc7 wpt-pr: 27256 UltraBlame original commit: 84ac1dad84575a71ebc6ad87ce7a6f71d6a1f864
…om `auto` to match the latest proposal, a=testonly Automatic update from web-platform-tests Update `SlotAssignmentMode` to `name` from `auto` to match the latest proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it. -- wpt-commits: 875f4c73ec1122cd0ea05580f6b56fda0ef71cc7 wpt-pr: 27256 UltraBlame original commit: 84ac1dad84575a71ebc6ad87ce7a6f71d6a1f864
…om `auto` to match the latest proposal, a=testonly Automatic update from web-platform-tests Update `SlotAssignmentMode` to `name` from `auto` to match the latest proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it. -- wpt-commits: 875f4c73ec1122cd0ea05580f6b56fda0ef71cc7 wpt-pr: 27256 UltraBlame original commit: 84ac1dad84575a71ebc6ad87ce7a6f71d6a1f864
…om `auto` to match the latest proposal, a=testonly Automatic update from web-platform-tests Update `SlotAssignmentMode` to `name` from `auto` to match the latest proposal (#27256) [By the latest proposal](whatwg/dom#860), `SlotAssignmentMode` value is changed to `name` from `auto`. This change follows it. -- wpt-commits: 875f4c73ec1122cd0ea05580f6b56fda0ef71cc7 wpt-pr: 27256
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.
This LGTM except for the set vs. list question.
@@ -2660,6 +2682,11 @@ indicated in the <a for=/>remove</a> algorithm below. | |||
<p>If <var>node</var> has an <a>inclusive descendant</a> that is a <a>slot</a>, then: | |||
|
|||
<ol> | |||
<li><p>for each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</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.
<li><p>for each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</a>, | |
<li><p>For each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</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.
Done.
Can we make the behavior of manually assigned nodes getting removed from a tree aligned with ID-ref as currently proposed in https://github.com/whatwg/html/pull/3917/files ? Namely, removal doesn't delete the assigned'ness permanently but merely makes it invisible. Once the node is inserted back as a child of the same shadow host, it would reappear. |
readonly attribute Element host; | ||
attribute EventHandler onslotchange; | ||
}; | ||
|
||
enum ShadowRootMode { "open", "closed" }; | ||
enum SlotAssignmentMode { "manual", "name" }; |
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.
Does someone know when "auto"
became "name"
? The Chromium (shipped) implementation uses "auto"
. Usage is low, so we can probably still change this, but I'm curious if this was an accident.
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.
It was intentional because we may want to add a new assignment mode in the future. e.g. you could imagine we'd introduce a new mode where slots are assigned based on each custom element's local name, or maybe we'd add some kind of "brand" to custom element so that custom elements can be slotted based on "brand" so that all subclasses of a custom custom element will be assigned to a given slot, etc...
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.
Ahh ok, that makes sense. Thanks. I'll get the Chromium implementation changed ASAP.
@@ -2660,6 +2682,11 @@ indicated in the <a for=/>remove</a> algorithm below. | |||
<p>If <var>node</var> has an <a>inclusive descendant</a> that is a <a>slot</a>, then: | |||
|
|||
<ol> | |||
<li><p>for each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</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.
Done.
<li><p>for each <a>slot</a> <var>slot</var> in <var>node</var>'s <a for=tree>inclusive descendants</a>, | ||
if <var>slot</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a> whose <a for=tree>root</a>'s | ||
<a for=ShadowRoot>slot assignment</a> is "<code>manual</code>", then set <var>slot</var>'s | ||
<a>manually assigned nodes</a> to an empty set. |
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.
Removed.
then:</p> | ||
|
||
<ol> | ||
<li><p>Set <var>result</var> to <var>slot</var>'s <a>manually assigned nodes</a>.</p></li> |
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.
Ok, I have the changes made locally, but:
a) I don't think I have permission to push to this PR, so I'll need to create a fresh one. Is that correct?
b) It seems that master
became main
, and while I support that change, my Git-fu precludes me from being able to get changes. I'm going to pull a fresh fork and see if that helps. I wish git and GitHub were less hostile.
Suggestions for either of the above appreciated.
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.
Alright, I ended up just making a fresh PR for this set of changes. That is located here: https://github.com/whatwg/dom/pull/966/files
I suppose we should close this PR.
The explainer for this feature is here: https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Imperative-Shadow-DOM-Distribution-API.md
The issue discussion is here: 3534
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:
💥 Error: 500 Internal Server Error 💥
PR Preview failed to build. (Last tried on Jan 15, 2021, 7:33 AM UTC).
More
PR Preview relies on a number of web services to run. There seems to be an issue with the following one:
🚨 CSS Spec Preprocessor - CSS Spec Preprocessor is the web service used to build Bikeshed specs.
🔗 Related URL
If you don't have enough information above to solve the error by yourself (or to understand to which web service the error is related to, if any), please file an issue.