preact-custom-element icon indicating copy to clipboard operation
preact-custom-element copied to clipboard

Add automatic global style injection

Open wbern opened this issue 5 years ago • 3 comments

Fixes #47

wbern avatar Sep 01 '20 21:09 wbern

Wow, good insights! I'll be going through these!

wbern avatar Sep 04 '20 05:09 wbern

I'm not entirely sure I understand the need for this to be a feature of preact-custom-element. What's happening here is essentially a variant of something the platform has attempted and removed twice (piercing descendant combinator and <style scoped>). From what I recall at the time when those solutions were removed, it turned out to be extremely difficult to achieve desirable semantics + performance when copying whole stylesheets around. Instead, the current approach is to ratify and ship the new Shadow Parts specification.

My concern as it relates to preact-custom-element is that all current userland solutions have poor performance, since even basic optimizations like structural sharing are not possible. For that reason, I would very much like to avoid promoting anything that relies on these semantics. Additionally, manual stylesheet copying would be extremely difficult to support in combination with platform features like Shadow Parts, Declarative Shadow DOM and Template Instantiation.

As a thought: what about providing a list of stylesheets to inject into the shadow root? This would avoid the implicit copying issues, but still allow for selective style inheritance.

developit avatar Sep 04 '20 18:09 developit

@marvinhagemeister your thoughts on above? Before I put in any more work into the PR.

We could just put a callback right after the attachShadow call, so we in the userland can use a solution like this on our own?

wbern avatar Sep 07 '20 08:09 wbern