Skip to content
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

Closed
wants to merge 17 commits into from
Closed

Add Imperative Slot API #860

wants to merge 17 commits into from

Conversation

yuzhe-han
Copy link

@yuzhe-han yuzhe-han commented Apr 24, 2020

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.


💥 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

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
 [no address given] to inform them of the time this error occurred,
 and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.4.10 (Debian) Server at api.csswg.org Port 443</address>
</body></html>

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.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@yuzhe-han yuzhe-han requested a review from annevk April 29, 2020 16:34
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@yuzhe-han
Copy link
Author

@annevk,

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.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@yuzhe-han
Copy link
Author

Thanks for reviewing. I've uploaded a new revision for review.

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.

I think this looks good now, modulo a couple minor nits.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
yuzhe-han and others added 3 commits June 17, 2020 06:19
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
@annevk
Copy link
Member

annevk commented Jul 6, 2020

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.

@yuzhe-han
Copy link
Author

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.

@rniwa
Copy link
Collaborator

rniwa commented Aug 5, 2020

FWIW, what's being proposed here seems fine.

dom.bs Outdated Show resolved Hide resolved
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>
Copy link
Member

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.

Copy link
Author

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
Copy link
Member

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?

Copy link
Author

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>.
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Collaborator

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.

Copy link
Author

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.

dom.bs Outdated Show resolved Hide resolved
@domenic
Copy link
Member

domenic commented Oct 15, 2020

@yuzhe-han would you mind responding to @annevk's comments? It'd be good to get this merged; I understand Chrome has shipped this.

@yuzhe-han
Copy link
Author

@domenic,
Yes, sorry for the delay. I'll response to @annevk comment Tomorrow.

@yuzhe-han
Copy link
Author

@annevk,

I've update the spec. Please review.
The build error is due to the definition of "manually assigned nodes" not available in HTML spec yet.
Would that get resolved once the corresponding HTML spec is merged? Or do I need to do something?

Thanks.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
<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>.
Copy link
Member

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.

dom.bs Outdated Show resolved Hide resolved
dom.bs Outdated Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Oct 30, 2020

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.

@rniwa
Copy link
Collaborator

rniwa commented Nov 8, 2020

dom.bs Outdated Show resolved Hide resolved
<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.
Copy link
Collaborator

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

Copy link
Member

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?

Copy link
Collaborator

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed.

Base automatically changed from master to main January 15, 2021 07:32
tetsuharuohzeki added a commit to tetsuharuohzeki/wpt that referenced this pull request Jan 20, 2021
… proposal

[By the latest proposal](whatwg/dom#860),
`SlotAssignmentMode` value is changed to `name` from `auto`.

This change follows it.
rniwa pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 5, 2021
… proposal (#27256)

[By the latest proposal](whatwg/dom#860),
`SlotAssignmentMode` value is changed to `name` from `auto`.

This change follows it.
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 9, 2021
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Feb 10, 2021
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Feb 10, 2021
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Feb 10, 2021
…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
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Feb 11, 2021
…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
@annevk annevk requested review from domenic and rniwa February 22, 2021 10:17
Copy link
Member

@domenic domenic left a 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.

dom.bs Show resolved Hide resolved
@@ -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>,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<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>,

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@rniwa
Copy link
Collaborator

rniwa commented Feb 23, 2021

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" };
Copy link
Contributor

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.

Copy link
Collaborator

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...

Copy link
Contributor

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>,
Copy link
Contributor

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.
Copy link
Contributor

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>
Copy link
Contributor

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.

Copy link
Contributor

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.

@mfreed7 mfreed7 mentioned this pull request Apr 2, 2021
3 tasks
@annevk annevk closed this in acfe96b Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants