←back to thread

277 points merqurio | 3 comments | | HN request time: 0.436s | source
Show context
jfagnani ◴[] No.45113365[source]
Lit maintainer here. I should be going to bed, but I'll answer any questions if people have any!

Not sure why Lit showed up on the front page tonight :)

replies(11): >>45113424 #>>45113441 #>>45113454 #>>45113460 #>>45113948 #>>45113980 #>>45114324 #>>45115284 #>>45115810 #>>45115985 #>>45117006 #
1. jfagnani ◴[] No.45117006[source]
Lots of comments in here are about shadow DOM, so let me give my take in one place:

Yes, Lit uses shadow DOM by default (for good reasons, I think!) and yes you can turn it off component-by-component, but that does bring some challenges.

Shadow DOM is most fundamentally just a private branch of the DOM tree for a component's internal DOM details.

Frameworks have this implicitly with DOM defined in a component's template vs passed as children. But that distinction isn't visible to other code, the browser, and CSS. This is both good and bad.

The biggest thing this separate tree gives us is the ability to tell what nodes are "children" - those are the light DOM children. Once you can separate children from internals, you can build slots. Slots are holes in the internals that children get rendered into.

Without something like shadow DOM you can't have slots. And without slots you don't have interoperable composition and you don't have viable container elements. You need some way to place children in an element that isn't confused with the element's own DOM.

So to me, before encapsulation and style scoping, interoperable composition is the most important feature, and that's really why Lit defaults to shadow DOM on. Without it we'd need some special `.children` property and Lit's component composition suddenly wouldn't be compatible with everyone else.

But the style encapsulation is often a major pain for developers, especially if they're trying to integrate web components into an existing system with whole-page stylesheets. It's a big blocker to a lot of design systems porting to web components.

That's one reason I proposed something called "Open Styleable Shadow Roots"[1] which would let styles from outer scopes cascade into a shadow root - a way to break open style encapsulation but keep slots. It's been hard convincing browser vendors that this is needed, but I'm holding out hope that it makes progress soon.

[1]: https://github.com/WICG/webcomponents/issues/909

replies(2): >>45118308 #>>45118715 #
2. ulrischa ◴[] No.45118308[source]
We used to put a link to the overall stylesheet in the webcomponents. That works pretty good
3. skybrian ◴[] No.45118715[source]
Aren’t a lot of components leaf nodes, with no slots? Does the shadow dom have any benefits for them?