Re: The .shadowRoot property and WebComponents

On Fri, Mar 8, 2013 at 1:13 PM, Jonas Sicking <jonas@sicking.cc> wrote:
> Related to the ongoing discussion about whether to expose the shadow
> tree of web components by default or not, but somewhat orthogonal to
> it, I think there is a question of *how* to expose the web component
> shadow tree.
>
> If I understand things correct, the .shadowRoot property and the
> createShadowRoot function behaves very different on elements that have
> a shadow tree attached through the use of WebComponents, compared to
> if it doesn't.

There's no such distinction as far as I know, but maybe I am not
seeing something. By WebComponents, do you mean custom elements?

>
> With an element with no attached web component, a page can rely on the
> fact that it can use .createShadowRoot in order to attach its own
> custom shadow root to an element. And it can rely on that the
> .shadowRoot property is null if it hasn't called .createShadowRoot and
> returns the shadow root created using createShadowRoot otherwise.

The custom element should never rely on this. .shadowRoot returns the
youngest shadow root, and not necessarily the shadow root that you got
when calling .createShadowRoot. For example, an extension could have
created a shadowRoot even for a custom element.

>
> But if a webcomponent has attached a shadow tree, then the .shadowRoot
> and createShadowRoot API suddenly behaves differently.

I am trying, but still failing to see the difference. Can you help me
understand it a bit better?

>
> I think there's value in enabling authors to always use .shadowRoot
> and createShadowRoot in order to attach a "page level" shadow tree to
> an element, and that that should work independently of if a web
> component also has attached a shadow tree.

Shadow trees are not coupled with custom elements in any way. They're
just a DOM API custom elements could use.

> If there's shadow tree attached using both createShadowRoot and using
> web components, then the two extend each other using the <shadow>
> element the same way that multiple shadow trees attached using web
> components do.

Now I am lost :) Again, there's no distinction between createShadowRoot usage.

>
> So for the cases when a web component chooses to expose its shadow
> tree, it should do so using some other API than .shadowRoot.
>
> Another way to look at it is that for a web component that chooses
> *not* to expose its shadow tree, the .shadowRoot property should still
> be useable and show no signs of there being a shadow tree attached
> through WebComponents.

Can you help me understand what you meant by "attached through
WebComponents"? Perhaps this is where the dog is buried.

:DG<

Received on Friday, 8 March 2013 23:03:03 UTC