Most active commenters
  • jfagnani(4)
  • brazukadev(3)

←back to thread

277 points merqurio | 14 comments | | HN request time: 0.514s | source | bottom
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 #
akmittal ◴[] No.45113424[source]
Curious which web platform features are missing that are preventing Web components to complete with React(for application development not widgets)?
replies(3): >>45113473 #>>45114450 #>>45117663 #
1. jfagnani ◴[] No.45113473[source]
I think web components already compete extremely well for application development, and you see very complex apps built with Lit out there: Photoshop, Firefox, Chrome OS, Chrome DevTools.

Apps are well served because they have more control about how components are used: they can import the same shared styles into every component, take are to not double-register elements, etc.

But I think there are some important standards still missing that would open things up even more in the design system and standalone components side:

- Scoped custom element registries. This moves away from a single global namespace of tag names. Seems like it's about to ship in Safari. Chrome next.

- Open styleable shadow roots. Would allow page styles to flow into shadow roots. This would make building components for use with existing stylesheets easier.

- CSS Modules. Import CSS into JS. Shipping in Chrome. About to land in Firefox.

- ARIA reference target: make idref-based reference work across shadow roots

replies(4): >>45113731 #>>45114341 #>>45115411 #>>45117764 #
2. nisbet ◴[] No.45113731[source]
About CSS Modules – Are you referring to this? https://caniuse.com/mdn-javascript_statements_import_import_...

Seems like this feature was removed from Chrome.

replies(1): >>45113885 #
3. jfagnani ◴[] No.45113885[source]
Import assertions were replaced with import attributes (`assert` replaced by `with`).

See https://caniuse.com/mdn-javascript_statements_import_import_...

4. brazukadev ◴[] No.45114341[source]
> - Open styleable shadow roots

What people using web components want is to get rid of shadowDOM and not feel like they are deviating from the correct path. shadowDOM sucks, stop trying to convince the world that we are using it wrong. shadowDOM is the whole reason web components did not become mainstream (yet?).

replies(3): >>45115372 #>>45116150 #>>45117075 #
5. dtagames ◴[] No.45115372[source]
I disagree completely. Shadow DOM is a huge help and when combined with per-component CSS using the :host() and nesting pattern, makes for very small CSS files and very short CSS class names. In other words, as far away from Tailwind as you can get.

It's also possible to import shared CSS in a base class and add it with super.styles() so you don't lose anything.

6. notnullorvoid ◴[] No.45115411[source]
Please do not refer to CSS type imports in JS as CSS Modules.

CSS Modules has an established meaning for over a decade, one that is still relevant today. The CSS type imports are very different, and arguably worse.

Call them CSSStyleSheet imports of you need a name suggestion.

7. Ruphin ◴[] No.45116150[source]
Nothing in Web Components is forcing you to use ShadowDOM. Lit also allows you to make components without ShadowDOM if you prefer, because there are certainly cases where it can be necessary to do so (like for ARIA reference id-matching). For full single application development, it can feel like it gets in the way a lot, and you can make a good argument to use components without ShadowDOM in those contexts too.

All frontend "frameworks" do have some sort of solution to scope CSS to individual components, and without a similar solution, a native component system would not be viable. The implementation has its quirks, but it is a core capability that is necessary for some use cases. For third-party widgets or cross-application components like design systems, the ability to isolate your component from the site it is embedded in is very useful.

Think of shadowDOM as the web component alternative to scoped styles in Vue components (as an example). You don't have to use it, but it would be incredibly inconvenient if it wasn't included in the framework.

replies(1): >>45116254 #
8. brazukadev ◴[] No.45116254{3}[source]
> Nothing in Web Components is forcing you to use ShadowDOM

Yes. There is just one thing forcing someone to use shadowDOM: slots. You can't use slots without shadowDOM or at least use something like this.children to capture the content inside the <custom-element></custom-element>.

But that is quite the important feature lacking.

replies(1): >>45116375 #
9. no_wizard ◴[] No.45116375{4}[source]
In my mind this has always made no sense to me, why slots aren’t independent of the shadow dom.

Same thing with how css is handled, especially since we have @layer and @scoped now

replies(1): >>45117464 #
10. mock-possum ◴[] No.45117075[source]
What about shadow dom sucks?

How else do you achieve that level of encapsulation to enable portable components?

replies(2): >>45117471 #>>45117603 #
11. jfagnani ◴[] No.45117464{5}[source]
It's not possible to make slots work without a separate tree like shadow DOM. The browser can't tell what the container for a slot is vs what content should project into it.
12. brazukadev ◴[] No.45117471{3}[source]
You don't want to enable portable components all the time. If most of the components you use to create your app is made by yourself, those boundaries are annoying, not helpful.
13. Muromec ◴[] No.45117603{3}[source]
The point is you mostly don't want this level of encapsulation
14. Muromec ◴[] No.45117764[source]
>- ARIA reference target: make idref-based reference work across shadow roots

How is this even supposed to work if each shadow dom has it's own scope of ids? `#id#subid` or something?

What if I want to ref to the outside?

The whole thing is not made for web development.