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

Figure out terminology for Shadow DOM that everyone agrees on #382

Closed
annevk opened this issue Feb 16, 2016 · 50 comments
Closed

Figure out terminology for Shadow DOM that everyone agrees on #382

annevk opened this issue Feb 16, 2016 · 50 comments

Comments

@annevk
Copy link
Collaborator

annevk commented Feb 16, 2016

It's not clear to me there is a difference.

Also, does Shadow DOM work without there being a document? There is a lot of terminology around there not being a document at the root. Is that to account for shadow trees in something created through document.createElement() but never inserted? Will event dispatch there go through the shadow tree and such?

@hayatoito
Copy link
Contributor

Also, does Shadow DOM work without there being a document?

It should work, although the spec does not mention it clearly. That is the reason I can not define the terminology of component tree simply as either a document tree or shadow tree. I had to introduce the terminology of fragment tree and let the definition of component tree include a fragment tree as workaround.

A fragment tree is a node tree whose root node is, such as, the result of "document.createElement() but never inserted into a document".

Unfortunately, the spec had been unclear on this kind of topic. So I have introduced these terminologies recently.

The intention of the current spec is: Shadow DOM should work even for a composed tree (of component trees) whose root tree is not a document tree.

e.g.

  • distribution, e.g. slot.getAssignedNodes() does correctly return the result, resolving the distribution.
  • event dispatching - event dispatch go through the shadow tree.

In fact, Blink supports this.

AFAIR, there is no public discussion on this topic. Thus, it might be worth discussing that we really want to support this or not. A use case is not clear to me.

@esprehn, @sorvell, do you know a use case or the reason why we need to calculate distribution for such a composed tree whose root tree is not a document tree?

@annevk
Copy link
Collaborator Author

annevk commented Feb 16, 2016

I guess it makes sense to support that given that we also support event dispatch in such cases. However, I think we should try to iterate on the terminology some more.

I think it would be better to define a component tree as a tree whose root node is either a Document object or a ShadowRoot object (i.e., whose root node implements the Component mixin). What you call component tree today is no different from "node tree", which makes it less of a useful term. (And instead of defining fragment tree say the algorithm operates on a node tree and that it doesn't have to be a component tree necessarily.)

I'm a little confused with what the specification calls "composed tree" today. When we talked about "composed tree" elsewhere I had what the specification calls the "flat tree" in mind. Is the "composed tree" language really necessary vs just talking about a node tree's hosted shadow trees or some such? I'm probably missing something significant here, but it seems variants of what the specification calls "flat tree" is what we'll need to define most features.

@hayatoito
Copy link
Contributor

What you call component tree today is no different from "node tree"

Yeah, that's true.

Unfortunately, "component tree" become the same meaning of "node tree" at this commit:
963bce3

I was aware of this fact when committing this change, however, I had no better idea and do not want to replace all "component tree" with "node tree" at that time.

I'm a little confused with what the specification calls "composed tree" today. When we talked about "composed tree" elsewhere I had what the specification calls the "flat tree" in mind.

Yes. That's painful. Actually, my colleague objected when I tried to re-use the "composed tree" as other meaning because it might be confusing. But I thought that we had to do it before upstreaming. I wanted to get rid of ugly terminology of "tree of trees", so I decided to re-use "composed tree" as "tree of trees" because "composed tree" became a good candidate to replace "tree of trees", give that we started to use "composed XXX", such as "composed child", "composed parent", to represent a relationship within a tree of trees, where distribution is not involved at all.

Is the "composed tree" language really necessary vs just talking about a node tree's hosted shadow trees or some such?

I do not expect that we have to use the "composed tree" frequently. In most cases, we can simply use "in a composed document" or "inserted into a composed document". That is enough and will cover the most cases.

We might get rid of this terminology, "composed tree", but this is very useful concept to define relevant algorithms. I do not care how we call it. "tree of trees", "composed tree" or something else, anything is okay to me. But I just needed a terminology to represent "tree of trees" so far.

I'm probably missing something significant here, but it seems variants of what the specification calls "flat tree" is what we'll need to define most features.

Good question, however, I am not sure which is used frequently: "composed XXX" vs "flat XXX".

Hmm. I can not tell which is used frequently. Do you want to use "composed XXX" as frequent words?

@annevk
Copy link
Collaborator Author

annevk commented Feb 16, 2016

Thank you for explaining it once more. Much appreciated.

Yeah, "composed" makes sense for <script> I guess, since they should run even if they end up not being distributed. Events will use flat. Okay, I see why we want both. And then both also have the open/closed variants to complicate matters.

So composed tree is a node tree including its hosted composed trees. The hosted trees of a composed tree will always be shadow trees. (You can imagine an even bigger tree that includes <iframe>-like trees, so terminology-wise we should not name this something that would preclude that, I think.)

A flat tree is the result of distributing the composed tree.

I'd like to have clearer terms, but I'm having a hard time coming up with them.

@rniwa
Copy link
Collaborator

rniwa commented Feb 16, 2016

How about "slotted tree" instead of "composed tree"? "flattened tree" seems fine.

@annevk
Copy link
Collaborator Author

annevk commented Feb 16, 2016

@rniwa "slotted" sounds like distribution already happened, whereas "composed tree" in the specification refers to a node tree and the shadow trees it hosts (recursively).

@rniwa
Copy link
Collaborator

rniwa commented Feb 16, 2016

@annevk : "distribution" is distinct from "slotted" in that assignedNodes for example takes an extra argument to specify whether it's flattened or not.

@annevk
Copy link
Collaborator Author

annevk commented Feb 16, 2016

@rniwa given <shadow-host><script/></shadow-host> and a hosted shadow tree without <slot> element, is script part of the slotted tree? It is part of the specification-concept "composed tree".

@annevk
Copy link
Collaborator Author

annevk commented Feb 16, 2016

In #377 @rniwa suggested "connected" as an alternate name for "composed". That might also be good. "Composed" as a term for what is essentially already there seems weird. You'd expect "composed" to be some modification.

@rniwa
Copy link
Collaborator

rniwa commented Feb 16, 2016

@annevk : oh I see, it would be a bit confusing in that case. Yeah, "connected" sounds good to me.

@hayatoito
Copy link
Contributor

I do not worry much about the naming. These terminologies are used internally and we can rename them anytime without impacting web-facing APIs.

On the other hand, in term of interoperability, we should have a rough consensus on the following:

The intention of the current spec is: Shadow DOM should work even for a composed tree (of component trees) whose root tree is not a document tree.

Do we agree on this? See also #356 and #384 (comment) .

@sorvell, Polymer depends on this assumption, doesn't it?

@hayatoito
Copy link
Contributor

This also affects "slotchange" event. #288

If distribution should work for such a disconnected shadow tree, we have to decide whether slotchange events should be supported or not for such a shadow tree.

@annevk
Copy link
Collaborator Author

annevk commented Feb 17, 2016

I think it would be more consistent with the DOM if it did work. The DOM generally doesn't care what the root is for any particular feature to work or not work.

@annevk
Copy link
Collaborator Author

annevk commented Feb 17, 2016

I just read the event path algorithm and it appears #382 (comment) is wrong. Events no longer use the flat tree (they did before, right?). So now if you have <shadow-host><b/></shadow-host> and dispatch an event on <b> it will no longer go through the shadow tree, even if <b> is slotted/distributed.

@hayatoito
Copy link
Contributor

It go though the shadow tree. I mean the slot to where <b> is assigned also receives an event.

The basic idea of the event path has not changed, I think. The event path is almost the same to ancestor chains in a flat tree. The only difference is that event path also includes a shadow root and a slot.

The reason we can not use a flat tree as is is that we should include a shadow root in the event path.

@hayatoito
Copy link
Contributor

I think it would be more consistent with the DOM if it did work. The DOM generally doesn't care what the root is for any particular feature to work or not work.

I got it. Thank you.

@annevk
Copy link
Collaborator Author

annevk commented Feb 17, 2016

Ah yes it does. I was reading the algorithm incorrectly. "assigned" should probably be a term that is defined in some way and linked.

@annevk
Copy link
Collaborator Author

annevk commented Feb 18, 2016

I do not worry much about the naming. These terminologies are used internally and we can rename them anytime without impacting web-facing APIs.

FWIW, I would like us to care about it and reach agreement. It helps tremendously in communication if we are all on the same page and it will make merging Shadow DOM into other standards much easier if they all use the same terminology that we know will no longer change.

@hayatoito
Copy link
Contributor

Yeah, I agree. Let me think about it again.

Since it looks Shadow DOM should work in a shadow tree which is disconnected from a document, my preference is:

  1. composed tree (of component trees (or node trees))
    I don't have a strong opinion. I'm fine with composed tree. This terminology will not be used frequently, I think.
  2. composed {parent/child/...}
    I am fine with the current naming, composed XXX. It might be okay to rename it to deep XXX.
  3. component tree
    We can define it as either a document tree or a shadow tree.
  4. fragment tree and primary component tree.
    Remove it
  5. The usage of component tree in the current spec
    We can replace most of them with node tree.
  6. flat tree
    I'm fine with it.

@hayatoito
Copy link
Contributor

In general, I am fan of the current naming.

The mental model behind the scene is:

  • We are given multiple component trees. Each represents a unit of component.
  • Then, they are composed into a one giant tree (of trees). We call it composed tree (of component trees).
  • Then, we are flattening composed tree into a flat tree, which is delivered to a user.

@annevk
Copy link
Collaborator Author

annevk commented Feb 19, 2016

As @rniwa keeps pointing out there's also a "slotted tree", no?

I think it's a little confusing that we call it a tree of trees. You'd expect in such a scenario that e.g., a child represents a whole tree and not a node. A "composed child" however is defined to be a node. So either we define some kind of transformation node tree -> composed tree whereby it would no longer be a tree of trees, just a fuller node tree, or we make it a tree of trees.

@rniwa also objected to "component tree" but it seems like we can get away with just making that "node tree" almost everywhere.

@annevk
Copy link
Collaborator Author

annevk commented Feb 19, 2016

Or we stop pretending that "composed tree" is a thing and define needed terminology upon a "node tree" that digs into the shadow trees.

@annevk
Copy link
Collaborator Author

annevk commented Feb 26, 2016

@rniwa @hayatoito ping.

@hayatoito
Copy link
Contributor

It is not a good idea to use a slotted tree as a replacement of a composed tree. A concept of a composed tree can exist without a slot element. It represents a relationship between node trees, purely.

Any terminology which is related to distribution should not be involved there. We might add yet another slot-like element in the future. Thus, a composed tree should be a concept which is independent of any particular element.

I agree that the usage of current "composed XXX" is confusing. Let me think further how we can avoid this confusion. Hmm.
... and I am now thinking that re-using composed tree, which was used in another meaning in the past, is simply a bad idea due to the historical reason. I'm okay not to use composed tree if we have another good idea, as you suggested. Let me update this thread later when I have a clear idea.

@annevk
Copy link
Collaborator Author

annevk commented Feb 26, 2016

I did not mean to say that "slotted tree" would be a replacement, just that it was something that wasn't mentioned in your list that we maybe need to account for? I've been working on some other things since this was not moving forward. I'll try to make some time to come up with a proposal.

@rniwa
Copy link
Collaborator

rniwa commented Feb 26, 2016

I really dislike the name "component tree". I would suggest removing it in favor of "document tree" or "node tree".

@annevk annevk changed the title Difference between composed document and document flat tree Figure out terminology for Shadow DOM that everyone agrees on Feb 29, 2016
@rniwa
Copy link
Collaborator

rniwa commented Feb 29, 2016

Yes, shadow DOM should work in a disconnected node tree.

@smaug----
Copy link

I suspect he agrees with me, but who knows.

ha.

document tree or node tree don't hint anything in the name that they might deal with shadow dom too, so I'm rather strongly against using them in cases when there are nodes both in shadow DOM and in light DOM.
But node tree is fine for whatever subtree where there is a node as a root and one can use normal DOM accessors to get to the descendants. So inside shadow DOM it is fine.

And yes, shadow DOM shouldn't care about whether the host is in document or not.

@hayatoito
Copy link
Contributor

document tree or node tree don't hint anything in the name that they might deal with shadow dom too, so I'm rather strongly against using them in cases when there are nodes both in shadow DOM and in light DOM.

@smaug---- , could you help me to understand the point?
Does it mean you do not want to use a node tree if one of the nodes in the node tree is a shadow host?

@annevk
Copy link
Collaborator Author

annevk commented Mar 2, 2016

He's opposed to use the term node tree as something that is larger than what node tree is today (e.g., something that would include shadow hosts or hosted shadow trees). Using node tree for a tree where the root happens to be a shadow root is fine.

@hayatoito
Copy link
Contributor

Does it mean we can use a node tree only if it is a leaf (tree) in a composed tree?

e.g. B, C, E and F in http://w3c.github.io/webcomponents/spec/shadow/#example-composed-tree-of-component-trees

Sorry, I'm still confused... However, I think we will not extend the meaning of the node tree here.

Even if a node tree A includes a node B which is a shadow host, A still remains to be a node tree by the definition. A node tree A does not include a node in a shadow tree which B hosts. Thus, one node tree never includes both a light DOM and a shadow DOM.

@annevk
Copy link
Collaborator Author

annevk commented Mar 2, 2016

Indeed, a node tree can be used for any tree consisting of just nodes. That is what @smaug---- meant too.

@hayatoito
Copy link
Contributor

Yeah, that matches my understanding. It looks I misunderstood what @smaug---- meant. Sorry for the confusion.

Thus, is everything okay? Let me use a node tree in the spec, replacing a component tree, as a first step.

@annevk
Copy link
Collaborator Author

annevk commented Mar 2, 2016

I think everyone agrees that shadow trees should work irrespective of the shadow-host-including inclusive ancestor being document (i.e., in disconnected trees as you call them).

But I don't think we have a plan for the terminology yet.

@rniwa
Copy link
Collaborator

rniwa commented Mar 2, 2016

Why don't we always say "document tree or shadow tree"? There is no terminology more clear than that, and if anyone comes up with a better name, we can deploy it later.

@hayatoito
Copy link
Contributor

Why don't we always say "document tree or shadow tree"?

Shadow DOM should work for a node tree which is neither document tree nor shadow tree, which we just agreed on???

@annevk
Copy link
Collaborator Author

annevk commented Mar 2, 2016

@rniwa I'm not sure I follow how that can be used. HTML has "in a document" now. Meaning a node's ancestor is document. We need something like that, meaning a node's shadow-host-including inclusive ancestor is document. With shadow-host-including inclusive ancestor defined as a variant on https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor with hosts restricted to shadow roots.

We also need something where we apply an algorithm to a node tree and derive a flat tree. And that algorithm should maybe assert the node tree is not itself hosted.

We might need something for slotted too, though maybe since slotted is only exposed in a few places that does not need much extra other than algorithms for use by those methods.

@hayatoito
Copy link
Contributor

A DocumentFragment node can have an associated element named host.

Ops! I do not know this concept. Was this introduced for <template> originally? What a coincidence!

@annevk
Copy link
Collaborator Author

annevk commented Mar 2, 2016

It was introduced for the template element and the idea was that it would be used by shadow root too.

@rniwa
Copy link
Collaborator

rniwa commented Mar 2, 2016

Why don't we always say "document tree or shadow tree"?
Shadow DOM should work for a node tree which is neither document tree nor shadow tree, which we just agreed on???

I don't follow. A node tree's root node is either a Document, ShadowRoot, or something else, right? It's a shadow tree if the root node is a shadow tree, and document tree if its root node is a Document.

@rniwa I'm not sure I follow how that can be used. HTML has "in a document" now. Meaning a node's ancestor is document. We need something like that, meaning a node's shadow-host-including inclusive ancestor is document. With shadow-host-including inclusive ancestor defined as a variant on https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor with hosts restricted to shadow roots.

Didn't we say we use the term connected for that? So isn't that just a connected composed tree / disconnected composed tree?

@hayatoito
Copy link
Contributor

I don't follow. A node tree's root node is either a Document, ShadowRoot, or something else, right? It's a shadow tree if the root node is a shadow tree, and document tree if its root node is a Document.

Yeah, a couple of facts:

  • The root tree in a composed tree is not always a document tree.
  • A non-root tree in a composed tree is always a shadow tree.
  • A node tree which is not a shadow tree (such as DocumentFragment, a document tree and so on) is always the root tree in a composed tree.

e.g. The result of createElement('div'). That is a node tree that has only one node. We can not call it a document tree nor a shadow tree. This node tree itself is the root tree of a composed tree, which has only one node tree, by definition.

When we attach a shadow tree to this node, Shadow DOM should work in this composed tree, whose root tree is not a document tree.

Thus, "a document tree or a shadow tree" might not cover this case...

@hayatoito
Copy link
Contributor

I've removed component tree, primary component tree and fragment tree form the spec, and use node trees almost everywhere as a replacement.

Thus, the followings are remaining contentious bits, right?

  • composed tree (of node trees)
  • composed {parent/child/ancestor/descendant}

Other ideas so far:

  • slotted tree
  • Introduce connected/disconnected terminology?
  • shadow-host-including inclusive ancestor

Is there anything else?

Note that the spec has already defined the following terminologies, which we can use:

  • in a composed document: as an alias for 'a node is an inclusive composed descendant of the root element of document element', which we can use for what 'connected/disconnected' means.
  • shadow-host-including inclusive ancestor sounds the same meaning of inclusive composed ancestor, which the spec already defines.

@annevk
Copy link
Collaborator Author

annevk commented Mar 4, 2016

I was trying to figure out how as e.g., an <iframe> inside a shadow tree, you know your host element got inserted into a document. That led me to conclude that whatwg/dom#34 needs to be updated not only to notify descendants, but also nodes inside hosted shadow trees.

I'm still trying to figure out what the best primitive is to have there (if we need a distinct notification next to parent change or if ancestor change is sufficient for all nodes, basically, I guess it doesn't matter much).

If we add shadow trees to the mix though that ancestor becomes a shadow-host-including inclusive ancestor (or a inclusive composed ancestor per current Shadow DOM terminology). Is that still okay?

If the host element was inserted into a closed shadow tree (whose shadow-host-including inclusive ancestor was a document), what kind of events would be fired on the custom elements inside host element's shadow tree? We can't really tell them the ancestor that got inserted since that would leak the closed shadow tree. @domenic have you looked at these events yet for custom elements?

(Maybe this should be a distinct issue. On the other hand, I'm just trying to figure out what all the various primitives are since they're not really documented at the moment. And hopefully once we have the primitives we can figure out suitable terminology for them.)

@annevk
Copy link
Collaborator Author

annevk commented Mar 21, 2016

I think this is slowly being resolved by integration with the DOM Standard (and soon HTML Standard). If anyone has any concerns about that let me know.

@hayatoito
Copy link
Contributor

Now, the spec is not using the composed {parent/child/ancestor/descendant} terminologies.

As the next step, I am now trying to avoid terminologies which are related to "composed tree of node trees". I am now rewriting the spec so that we do not need to use "composed tree".

@hayatoito
Copy link
Contributor

I successfully updated the spec so that it does not depend on a concept of composed tree of node trees in normative sections.

I resolved almost all issues of the terminologies around:

  1. composed tree (of component trees (or node trees)) => No longer used in normative sections
  2. composed {parent/child/...} => Renamed to shadow-including xxx
  3. component tree => Removed, in favor of node trees
  4. fragment tree and primary component tree => Removed, in favor of node trees
  5. flat tree => Keep it

I think we can close this issue now.

@trusktr
Copy link
Contributor

trusktr commented May 18, 2020

If someone asks me what a "flat tree" or "composed tree" is when I am describing Shadow DOM to them, where should I link them to?

This thread is one of the top results on Google, at least for me (we know Google has bias on a per user basis so maybe the result is more likely to show up for me than someone else). Even in an incognito window, this thread is still the third result (for me, while in Oakland, CA).

The original document, for example https://www.w3.org/TR/2015/WD-shadow-dom-20151006/, was nice because it explained the topic more clearly and with visual diagrams.

But now, those documents are "outdated", and clicking forward to the new documents leads to a place that is far less helpful, does not include concise descriptions of the concepts, and does not include tree diagrams. It seems to be a regression in terms of helping people understand the concepts (like the original document did).

It seems virtually impossible for (especially new) people to learn (from official documents) what ShadowDOM is, and how the tree works and how it renders (f.e. rendering from the "flat tree").

Have I missed another document somewhere?

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

No branches or pull requests

5 participants