Intent to Implement: Default Style for Custom Elements

110 views
Skip to first unread message

Takayoshi Kochi

unread,
Mar 29, 2018, 4:34:45 AM3/29/18
to blink-dev

Contact emails

ko...@chromium.org, rak...@chromium.org


Explainer

Explainer


Design doc/Spec

Design doc

No spec is formally written yet.  Based on the initial implementation feedback, changes

will be added to the CSS/HTML specs, and further details should be worked out.


Implementation tracking bug is crbug.com/824684


Summary

Give an ability to specify default style for custom elements when they are registered.


The new API surface is to add a “style” option whose value is an instance of

CSSStyleSheet in Custom Element’s definition option. E.g.

window.customElements.define('my-element', MyElement, { style: styleSheet });


Motivation

The background for this was a proposal at webcomponents#468.


In short,

  • Give a capability like UA-stylesheet to custom elements

  • Avoid overhead of adding stylesheet in its shadow root


Using custom elements with its default style has had overhead of constructing shadow root

and style for each instance, which made it slower than native HTML elements.

The proposal is to reduce the overhead to achieve performance as much closer to native

elements as possible (e.g. crbug.com/789729).


Risks

Interoperability and Compatibility

There was rough consensus to move this forward in the last W3C Web Components F2F

in March 2018 (minutes). The API is still in design phase and is subject to change.

The objective of implementing this is to get early feedback on performance to decide

how we move forward.


Edge: not opposed

Firefox: Public support

Safari: Public support

Web developers: Positive


Ergonomics

This will make using custom elements styling easier.


Activation

This is an incremental extension to the current Custom Elements APIs, and will not break any

backward compatibility.


Debuggability

As an implementation detail, we might add a fake shadow root which should be invisible to web and

inspector, so some changes

may be necessary to the inspector code.

Matching CSS rules can be coming from not in stylesheet in HTML (e.g. constructable
stylesheet object).

Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes


Link to entry on the feature dashboard

https://www.chromestatus.com/features/5140940264046592


Requesting approval to ship?

No


---
Takayoshi Kochi

Anne van Kesteren

unread,
Mar 29, 2018, 7:10:05 AM3/29/18
to Takayoshi Kochi, blink-dev
On Thu, Mar 29, 2018 at 10:34 AM, Takayoshi Kochi <ko...@chromium.org> wrote:
> Design doc

Is there a reason for this document to have restricted access? I'm
somewhat curious how no new architecture on top of shadow root
stylesheets, while :host still has to do something is proposed to be
resolved.


--
https://annevankesteren.nl/

Rakina Zata Amni

unread,
Mar 29, 2018, 9:23:45 AM3/29/18
to ann...@annevk.nl, Takayoshi Kochi, blink-dev
 Is there a reason for this document to have restricted access?
Whoops, sorry. I changed it so that it can be accessed by anybody with the link now.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADnb78gARfifKUeRdKc-3j3O_JRUhj7Qs2rvY6aXMAaTz%3DSXOQ%40mail.gmail.com.

Anne van Kesteren

unread,
Mar 29, 2018, 10:10:40 AM3/29/18
to Rakina Zata Amni, Takayoshi Kochi, blink-dev
On Thu, Mar 29, 2018 at 3:23 PM, Rakina Zata Amni <rak...@chromium.org> wrote:
>> Is there a reason for this document to have restricted access?
>
> Whoops, sorry. I changed it so that it can be accessed by anybody with the
> link now.

Thanks, my main worry with this setup is how we'd end up explaining it
in the standards and what kind of other unexpected side effects a
"fake shadow root" might bring us in the future. It seems like a
rather magical concept.


--
https://annevankesteren.nl/

Rune Lillesveen

unread,
Apr 3, 2018, 10:57:40 AM4/3/18
to Rakina Zata Amni, ann...@annevk.nl, Takayoshi Kochi, blink-dev
I'd really prefer the proposals in the super-long thread[1], also supported by [2], which lean towards UA origin and disallowing complex selectors.

[2] https://drafts.csswg.org/css-scoping/#default-element-styles

--
Rune Lillesveen

mo...@google.com

unread,
Aug 24, 2018, 6:01:18 PM8/24/18
to blink-dev
We are experimenting different designs to find the best way.
I am implementing :element selector in this CL.
Reply all
Reply to author
Forward
0 new messages