Skip to content

Slots in a flat tree #308

Closed
Closed

Description

@rniwa

Composition Algorithm defined in section 4.1 "unwraps" slots by re-distributing distributed nodes of a distributed slot by invoking Distributed Nodes Algorithm in section 3.3.

However, I don't think that should happen. In the world where re-distribution is explicit, there is no point in stripping out slot elements. It's better to treat a slot element like any other element and re-distribute it on its entirely. This will make the distribution/composition algorithm much simpler and allows slot element to be styled properly.

@hober @othermaciej @annevk @travisleithead

Activity

  1. sorvell commented on Sep 2, 2015

    @sorvell

    Where would the distributed nodes be projected?

    It would be problematic if they are projected inside the <slot>. In that case one couldn't, for example, project elements into an element that has display: flex.

    <x-b>
      SR
        <div style="display: flex;"><slot></slot></div>
      <div>flex item?</div>
    
  2. hayatoito commented on Sep 2, 2015

    @hayatoito
    Contributor

    Thanks for the feedback.

    I'd like to treat a slot, as well as an insertion point, as DocumentFragment, as ShadowRoot actually is. That has been in my mental model for a long time. By considering both as DocumentFragment, everything became clear to me.

    I guess someone doesn't like a slot element being left in the document composed tree, given a shadow root is not left in the document composed tree.
    IMO, a slot, and an old insertion point as well as a shadow root, should not be on any more than needed to support the distribution and the composition mechanism.

  3. rniwa commented on Sep 2, 2015

    @rniwa
    CollaboratorAuthor

    It would be problematic if they are projected inside the <slot>. In that case one couldn't, for example, project elements into an element that has display: flex.

     <x-b>
      SR
        <div style="display: flex;"><slot></slot></div>
      <div>flex item?</div>
    

    I see. That's a pretty good argument for keeping the currently spec'ed behavior although it feels like we're working around the limitation of CSS.

    If we had a new display type like display: ignore which replaces a node with its children for the purpose of box generations, we wouldn't need to do this, right?

    One thing I don't like about the current model is the discrepancy between the composed tree as exposed to CSS and the tree event dispatching takes place. Namely, the event path will include the slot element that is a deep ancestor of the target.

  4. rniwa commented on Sep 2, 2015

    @rniwa
    CollaboratorAuthor

    I'd like to treat a slot, as well as an insertion point, as DocumentFragment, as ShadowRoot actually is. That has been in my mental model for a long time. By considering both as DocumentFragment, everything became clear to me.

    I don't understand what you mean by this. A slot element is an element so it certainly can't be a document fragment.

    Moreover, as things stand, the concept of "slot" isn't well defined in the spec. It's a "defined location" according to the spec but there are no definitions of "defined"-ness or what a "location" is. It could be a (node, offset) pair like a boundary point or it could be a node. Whatever it is, it needs to be precisely defined. See issues #306 and #307.

  5. hayatoito commented on Sep 2, 2015

    @hayatoito
    Contributor

    Thanks. I think we can close this issue. Please feel free to re-open this if required.
    Let me address some comments as separate issues, like #306.

    One more note I can add here is that we might want to support the following use case in the future:

     <table>
      SR
        <slot name="thead"></slot>
        <slot name="tr"></slot>
        ...
    
      <thead slot="thead">...</thead>
      <tr slot="tr">...</tr>
      <tr slot="tr">...</tr>
      ...

    In this case, I guess no one is pleasant that <slot> would appear between <table> and <thead> in the composed tree.

  6. rniwa commented on Sep 2, 2015

    @rniwa
    CollaboratorAuthor

    I don't think we want to do this just for the styling use cases mentioned here. I think we just need to set display: contents as the default sheet sheet on slot elements as follows and that should address both use cases mentioned here.

    slot { display: contents; }

    To put it another way, the composed tree is only useful to CSS box generation and the current distribution algorithm is trying to avoid box generation for slot element manually. And I'm saying that it's not necessary or desirable since box generation is inherently a CSS concern and should be dealt as such.

    We can preserve the behavior of not generating boxes (so that tables, flex boxes, ec... work) without having to do it manually in the algorithm by simply relying on a CSS feature such as display: contents or a new concept in CSS if one is needed.

    One huge benefit of this approach is that the author can then override display property, e.g. to show borders around slot elements, if they wanted to, and removes one more magic from shadow DOM.

  7. reopened this on Sep 2, 2015
  8. hayatoito commented on Sep 3, 2015

    @hayatoito
    Contributor

    One huge benefit of this approach is that the author can then override display property, e.g. to show borders around slot elements, if they wanted to, and removes one more magic from shadow DOM.

    FYI, we can get this benefit by wrapping a slot with an arbitrary element, like:

    Before:

    <shadow-host>
      <shadow-root>
        <slot name="xxx">
      <div slot="xxx">...</div>
      <div slot="xxx">...</div>
    

    After:

    <shadow-host>
      <shadow-root>
        <div class="wrapper">
          <slot name="xxx">
      <div slot="xxx">...</div>
      <div slot="xxx">...</div>
    
  9. rniwa commented on Sep 3, 2015

    @rniwa
    CollaboratorAuthor

    Right, but that's not really my point. The benefit of making this behavior reliant on CSS is that we'll decouple shadow DOM's distribution algorithm from the matter of box generation so that authors can figure it as they wish.

  10. dglazkov commented on Sep 3, 2015

    @dglazkov
    Contributor

    I think we should try this. We've attempted this before, and failed for a reason I can't remember. I would love to explain <slot> as just a UA style that's slot { display:contents; }.

  11. hayatoito commented on Sep 3, 2015

    @hayatoito
    Contributor

    I see. I think one good news is this is an implementation detail because users can't see the difference unless users try to style <slot> elements, right? Both approaches should have the same result, I think, because we won't expose an API for composed tree traversal.

  12. annevk commented on Sep 3, 2015

    @annevk
    Collaborator

    Isn't deepPath using the composed tree?

  13. 43 remaining items

  14. changed the title [-]Composition Algorithm shouldn't unwrap slots[/-] [+]Slots in a flat tree[/+] on Mar 24, 2016
  15. hayatoito commented on Mar 28, 2016

    @hayatoito
    Contributor

    My biggest concerns are:

    1. How can we trust the feature of {display: contents}? Can we be 100% sure this will be successful? It looks there is no other spec which bets on its success, AFAIK. Only Shadow DOM looks the early adapter.
    2. Suppose that we support "a slot in a flat tree" in the spec, and developers start to style a slot element, that's un-reversible change.
      Later, when we find "{display: contents}" is not a thing, it's too late. We can not change the behavior without breaking the Web site.

    Thus, I have to be careful to add a slot in a flat tree. If we support it, that means that Shadow DOM will fail if {display: contents} fails.

    Is there any significant benefit of adding a slot in a flat tree, which is worth having such a great risk?
    Note that we can support "slots in a flat tree" anytime later when we can feel "{display: contents}" is widely accepted.

    I am not opposing to "slots in a flat tree", but I am afraid that it's too risky today, and today is not the day.

    @tabatkins, WDTY? Do you have a good feeling that "{display: contents}" will become successful??

  16. rniwa commented on Mar 28, 2016

    @rniwa
    CollaboratorAuthor

    In general, it's a good idea to minimize the number of new "magics" we introduce to the Web. Being able to describe/de-sugar slot element's behavior in terms of display: contents would be "explaining" the platform and "building on top of primitives". Introducing a shadow-DOM specific CSS box generation mechanism is anti-pattern in this regard (against the Extensible Web Manifest).

  17. rniwa commented on Mar 28, 2016

    @rniwa
    CollaboratorAuthor

    On more concrete examples, I already hit an interoperability problem with Chrome whereby which it doesn't respect display: none on slot elements whereas WebKit did. Chrome's behavior of ignoring display:none was rather surprising for me as an author. In addition, having to use :slotted(*) because styles on slot elements would be ignored has been really annoying.

  18. tabatkins commented on Mar 28, 2016

    @tabatkins

    display: contents is useful on the CSS side for a number of things; Shadow DOM is only one of them.

    I can't say whether it will succeed or not, as that depends on browser vendors implementing it. That said, I think Firefox has done so.

  19. hayatoito commented on Mar 31, 2016

    @hayatoito
    Contributor

    @tabatkins, thanks.

    Can I confirm one more thing? Does the following HTML work as expected (from the view of the spec)?

    <div style="display: flex;">
      <div style="display: contents;">
        <div>flex item 1</div>
        <div>flex item 2</div>   
        ....
      </div>
    </div>
    

    This is the raised concern from @sorvell in #308 (comment).

  20. tabatkins commented on Mar 31, 2016

    @tabatkins

    Yes, it works as expected, per spec. I think this works in Firefox right now if you want to test it.

  21. hayatoito commented on Mar 31, 2016

    @hayatoito
    Contributor

    @tabatkins , thanks. I appreciate that.

    Then, it looks reasonable to support "add slots in a flat tree" with UA-style "slot { display:contents; }" in the spec. I'll update the spec.

    Since Blink has not supported "display: contents" yet and its engine requires a huge rewrite to support "a slots in a flat tree", Blink's initial implementation of v1 will not fully respect it.

    If someone has a concern about this decision, please let us know that.

  22. esprehn commented on Apr 1, 2016

    @esprehn

    Looking at WebKit I think right now slotted elements inherit from the parent of the <slot>, and webkit only respects display: none. That is doing slot { display: block; } has no effect.

    I'm very hesitant to ship with matching behavior, it doesn't seem like that's how display: contents was supposed to work. display: contents also has implications, for example are counter increments considered when declared on the slot? What about quoting level? Does slot::before and slot::after work? does display: contents disable ::before? (I hope so). What about slot::first-line ?

    I'd like to work out the details before we commit to making display: contents be a thing, and slot having a dependency on that technology. The current system is easy to explain, is just gone by the time styles are computed. There's no subtle rules for what does and does not apply.

  23. tabatkins commented on Apr 1, 2016

    @tabatkins

    Looking at WebKit I think right now slotted elements inherit from the parent of the , and webkit only respects display: none. That is doing slot { display: block; } has no effect.

    I'm very hesitant to ship with matching behavior, it doesn't seem like that's how display: contents was supposed to work.

    Correct, that is a broken implementation. Firefox has, afaik, a real implementation of display:contents.

    display: contents also has implications, for example are counter increments considered when declared on the slot? What about quoting level? Does slot::before and slot::after work? does display: contents disable ::before? (I hope so). What about slot::first-line ?

    All defined by https://drafts.csswg.org/css-display/#valdef-display-contents.

    Counters work on the element tree; they're not disturbed by box-tree manipulation. (If they were, then the 'order' property would mess with them too.) Quotes aren't very specific (they're defined by language lingering from CSS2, when we were much less explicit about the element/box/fragment divisions), but they should work the same. Pseudo-elements still generate as normal.

  24. rniwa commented on Apr 5, 2016

    @rniwa
    CollaboratorAuthor

    Telecom agreement: We'd spec this as display: contents. While there are unknowns with respect to its behavior, and there is disagreements within Google regarding this feature, it seems okay to use this given WebKit and Gecko are implementing this feature in near future.

  25. added a commit that references this issue on Jul 30, 2025
    f279770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions