This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 15611 - [Shadow]: Consider element.createShadowRoot as API for creating ShadowRoot objects.
Summary: [Shadow]: Consider element.createShadowRoot as API for creating ShadowRoot ob...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
: 17447 (view as bug list)
Depends on:
Blocks: 18428
  Show dependency treegraph
 
Reported: 2012-01-18 17:35 UTC by Elliott Sprehn
Modified: 2012-11-27 19:11 UTC (History)
1 user (show)

See Also:


Attachments

Description Elliott Sprehn 2012-01-18 17:35:27 UTC
Read only access to every ShadowRoot must be provided for each element to support tools. Without it something like Readability wouldn't be possible because there's no way to access the content of the page that's inside the shadow DOM.

This also makes tools like Google Feedback impossible to build because there's no way to access the nodes  in the shadow DOM for rendering in screenshots. Without the addition of CanvasRenderingContext2D #renderElement() this cripples HTML screenshot tools.

In general the API appears to be backwards because the ShadowRoot constructor is invoked directly instead of being created through a factory method like createElement().

root = element.createShadowRoot() => new root.
element.shadowRoots => list of roots.
Comment 1 Dimitri Glazkov 2012-01-18 18:26:43 UTC
Thanks for the feedback! There are two issues reported here:

(In reply to comment #0)
> Read only access to every ShadowRoot must be provided for each element to
> support tools. Without it something like Readability wouldn't be possible
> because there's no way to access the content of the page that's inside the
> shadow DOM.
> 
> This also makes tools like Google Feedback impossible to build because there's
> no way to access the nodes  in the shadow DOM for rendering in screenshots.
> Without the addition of CanvasRenderingContext2D #renderElement() this cripples
> HTML screenshot tools.

This is bug 15409.

> 
> In general the API appears to be backwards because the ShadowRoot constructor
> is invoked directly instead of being created through a factory method like
> createElement().
> 
> root = element.createShadowRoot() => new root.
> element.shadowRoots => list of roots.

This is new. I'll repurpose the bug to track this. So far, my thinking is that "new ShadowRoot(..)" is shorter, and doesn't require extending HTMLElement API surface.
Comment 2 Elliott Sprehn 2012-11-02 20:42:12 UTC
(In reply to comment #1)
> ...
> This is new. I'll repurpose the bug to track this. So far, my thinking is
> that "new ShadowRoot(..)" is shorter, and doesn't require extending
> HTMLElement API surface.

We're already extending the API surface with public shadows, and having a constructor that has side effects is very weird. I can't think of any other place in the platform where constructing an object has side effects like this (and it's usually considered a code smell).

It's particularly weird in the implementation of WebKit as we call ShadowRoot::create(this) often and discard the return value which is non-obvious to someone looking at the code. Once we expose public shadows people may do the same thing:

function doSomething() {
  // Not obvious this does anything.
  new ShadowRoot(element);
}

element.oldestShadowRoot.appendChild(...);

so I'd propose addShadowRoot() which is the same number of characters and models what's going on better.

element.addShadowRoot()
Comment 3 Dimitri Glazkov 2012-11-20 00:05:32 UTC
http://dvcs.w3.org/hg/webcomponents/rev/e0dfe2ac8104
Comment 4 Dimitri Glazkov 2012-11-27 19:11:38 UTC
*** Bug 17447 has been marked as a duplicate of this bug. ***