W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2013

[webcomponents]: Re-imagining shadow root as Element

From: Dimitri Glazkov <dglazkov@google.com>
Date: Mon, 18 Mar 2013 13:53:37 -0700
Message-ID: <CADh5Ky0igHaGu_rVf+eYskLrz9xcmBMBkdVdDA4BX_KDRsQBFQ@mail.gmail.com>
To: public-webapps <public-webapps@w3.org>
Cc: Elliott Sprehn <esprehn@google.com>, Scott Miles <sjmiles@google.com>, Adam Klein <adamk@google.com>, Steve Orvell <sorvell@google.com>, Hajime Morrita <morrita@google.com>, Rafael Weinstein <rafaelw@google.com>, Ojan Vafai <ojan@google.com>, Alex Komoroske <komoroske@google.com>, Matthew McNulty <mmcnulty@google.com>
Last Friday, still energized after the productive Mozilla/Google
meeting, a few of us (cc'd) dug into Shadow DOM. And boy, did that go
south quickly! But let's start from the top.

We puzzled over the the similarity of two seemingly disconnected problems:

a) ShadowRoot is a DocumentFragment and not an Element, and
b) there is no declarative way to specify shadow trees.

The former is well-known (see

The latter came into view very early as a philosophical problem
(provide declarative syntax for new imperative APIs) and much later as
a practical problem: many modern apps use a "freeze-drying"
performance technique where they load "as-rendered" HTML content of a
page on immediately (so that the user sees content immediately), and
only later re-hydrate it with script. With shadow DOM, the lack of
declarative syntax means that the content will not appear
"as-rendered" until the script starts running, thus ruining the whole
point of freeze-drying.

We intentionally stayed away from the arguments like "well, with
custom elements, all of this happens without script". We did this
precisely because we wanted to understand what "all of this happens"
actually means.

Trapped between these two problems, we caved in and birthed a new
element. Let's call it <shadowroot> (Second Annual Naming Contest
begins in 3.. 2.. ).

This element _is_ the ShadowRoot. It's deliciously strange. When you
do div.appendChild(document.createElement('shadowroot')), the DOM:

0) opens a magic wormhole to the land of rainbows and unicorns (aka
the Gates of Hell)
1) adds <shadowroot> at the top of div's shadow tree stack

This behavior has three implications:

i) You can now have detached ShadowRoots. This is mostly harmless. In
fact, being able to prepare ShadowRoot instances before adding them to
a host seems like a good thing.

ii) ShadowRoot never appears as a child of an element. This is desired
original behavior.

iii) Parsing HTML with <shadowroot> in it results in loss of data when
round-tripping. This is hard to swallow, but one can explain it as a
distinction between two trees: a document tree and a composed tree.
When you invoke innerHTML, you get a document tree. When you invoke
(yet to be invented) innerComposedHTML, you get composed tree.

Alternatively, we could just make appendChild/insertBefore/etc. throw
and make special rules for <shadowroot> in HTML parser.


* The shadow root is now an Element with localName and defined DOM behavior
* There's now a way to declare shadow trees in HTML
* Just like DocumentFragment, neatly solves the problem of root being
inserted in a tree somewhere


* We're messing with how appendChild/insertBefore work

What do you folks think?

A. This is brilliant, I love it
B. You have made your last mistake, RELEASE THE KRAKEN!
C. I tried reading this, but Firefly reruns were on
D. ___________________________

Received on Monday, 18 March 2013 20:54:06 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:59 UTC