Most active commenters
  • jfagnani(9)
  • brazukadev(3)
  • troupo(3)
  • Muromec(3)

←back to thread

277 points merqurio | 40 comments | | HN request time: 0.539s | source | bottom
1. 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 #
2. 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 #
3. polyrand ◴[] No.45113441[source]
Hi! Not really a question, but just an appreciation message. I haven't used the full "Lit" package a lot, but "lit-html" is incredibly useful.

I use it in almost all my personal websites. And when I don't use it, I end up reinventing half of it and realize I should have used it from the start. This command is in most of my projects:

  curl -L https://cdn.jsdelivr.net/npm/lit-html@3/lit-html.js -o ${project}/lit-html.js
I've never felt I'm using a framework or anything that deviates from Vanilla JS and valid HTML, which is why using it hardly causes any more cognitive load than using regular string templates and JavaScript functions. Which is something that I can't say about other frontend tools.

Another thing I like from Lit is that with the CDN bundle, it's straightforward to experiment and use all the features without needing a build step.

4. preommr ◴[] No.45113454[source]
Any whispers of something like lit being made part of the webcomponents standard?

Web components are nice because they're browser-native, but they don't support reactivity, which in hindisight, is a massive oversight, issue, whatever you want to call it - it's hindered adoption.

Lit is nice because there's a very straightforward progression from web components.

replies(1): >>45113502 #
5. edweis ◴[] No.45113460[source]
Is there a way to efficiently use Lit without using a bundler?
replies(1): >>45113486 #
6. 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 #
7. jfagnani ◴[] No.45113486[source]
Lit's just a JavaScript library published as standard modules, so it doesn't require a bundler. Using Lit efficiently is the same as using any other library.

HTTP/3, import maps, and HTML preloads can make unbundled app deployment almost reasonable in some cases. You'd still miss out on minification and better compression form a bundle. Shared compression dictionaries will make this better though.

8. jfagnani ◴[] No.45113502[source]
Lit has always been designed partially as a prototype for where web component standards could go in the future. That's a big reason Lit is fairly conservative and un-opinionated. It doesn't try to undo or paper-over any of the DOM APIs, but add to them instead.

There is a proposal in TC39 for native signals, which I think would make a huge dent towards library-less reactivity.

I'm also working on a proposal for native reactive templating which would more-or-less obsolete lit-html. I wrote about the idea some on my blog:

- The time is right for a DOM templating API https://justinfagnani.com/2025/06/26/the-time-is-right-for-a...

- What should a native DOM templating API look like? https://justinfagnani.com/2025/06/30/what-should-a-dom-templ...

replies(3): >>45113529 #>>45114361 #>>45114436 #
9. ◴[] No.45113529{3}[source]
10. nisbet ◴[] No.45113731{3}[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 #
11. jfagnani ◴[] No.45113885{4}[source]
Import assertions were replaced with import attributes (`assert` replaced by `with`).

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

12. iammrpayments ◴[] No.45113948[source]
Are properties reactive?

Can I reassign name in the example by using document.querySelector?

replies(1): >>45114046 #
13. mkleczek ◴[] No.45113980[source]
Thanks for your great work.

I can't find clear information about how re-rendering and stateful third-party components interact.

Let's say I have a stateful data table web component that I use in the template. Is it going to be re-created every time the template is re-rendered (loosing its internal state)?

replies(1): >>45114062 #
14. jfagnani ◴[] No.45114046[source]
Yes!
15. jfagnani ◴[] No.45114062[source]
Thanks!

Elements are kept stable as long as the template containing them is rendered.

The template docs try to get this across by saying that Lit "re-render only the parts of template that have changed." Maybe that needs more detail.

There are details here: https://github.com/lit/lit/blob/main/dev-docs/design/how-lit...

16. krikou ◴[] No.45114324[source]
Here just to say thank you for Lit! It is a real pleasure to use (for simple and complex use-case).

Sometimes, I am wondering why it is not more widely used ...

17. brazukadev ◴[] No.45114341{3}[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 #
18. lenkite ◴[] No.45114361{3}[source]
I hope there can be ways without JS to populate templates with data - autoloaded from sources. This would tremendously increase the number of JS free web-sites. Also wish the web-components standard did not mandate the use of JS. It should be possible to define simple web-components (HTML+CS) declaratively and have this officially supported in standard and implementation
replies(1): >>45120190 #
19. troupo ◴[] No.45114436{3}[source]
> Lit has always been designed partially as a prototype for where web component standards could go in the future.

> There is a proposal in TC39 for native signals,

Which originated (or the modern versions of signals originated) in Solid, not in Lit.

Let me quote the readme: https://github.com/tc39/proposal-signals

--- start quote ---

The current draft is based on design input from the authors/maintainers of Angular, Bubble, Ember, FAST, MobX, Preact, Qwik, RxJS, Solid, Starbeam, Svelte, Vue, Wiz, and more…

-- end quote ---

replies(1): >>45114910 #
20. troupo ◴[] No.45114450[source]
You can start with the Web Components Community Report: https://w3c.github.io/webcomponents-cg/2022.html

Or with opinions like this: https://dev.to/ryansolid/web-components-are-not-the-future-4...

O if you want to go down the technical rabbit hole, you can search for all the issues people have with them, e.g.: https://x.com/Rich_Harris/status/1841467510194843982

21. nchmy ◴[] No.45114910{4}[source]
They never claimed that signals originated in lit. They were just responding to the comment that there's no native reactivity in web components...
22. dtagames ◴[] No.45115284[source]
Nice to see you here and THANK YOU for the amazing tool that is Lit. It's everything you want from a framework without a framework getting in your way.

I'm sold and build all my work and personal apps with it and have for many years. I wrote this article about why in 2022:

Getting Started with Web Components & Lit

https://medium.com/gitconnected/getting-started-with-web-com...

replies(1): >>45115526 #
23. dtagames ◴[] No.45115372{4}[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.

24. notnullorvoid ◴[] No.45115411{3}[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.

25. dboon ◴[] No.45115526[source]
Thanks, great article. It’s always good to understand the context of where libraries fit into the web ecosystem and why they exist. Much appreciated!
26. dan353hehe ◴[] No.45115810[source]
I am not the one who submitted it. But someone mentioned it last night:

https://news.ycombinator.com/item?id=45107388

I assume someone else looked it up and liked it enough to submit it.

27. gitaarik ◴[] No.45115985[source]
What I wonder is whether there are any developments related to Lit regarding server-side rendering (SSR). This is one of the reasons I'm experimenting with Svelte now. To me Lit was taking away frustrations with the inefficiencies of React. But for me Svelte seems to fill that gap too, and it also has SSR, among other niceties. But I do like the philosophy of Lit & Web Components. Sometimes I think a framework that would be like Svelte but uses Lit under the hood would seem like the best of both worlds.
28. Ruphin ◴[] No.45116150{4}[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 #
29. brazukadev ◴[] No.45116254{5}[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 #
30. no_wizard ◴[] No.45116375{6}[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 #
31. 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 #
32. mock-possum ◴[] No.45117075{4}[source]
What about shadow dom sucks?

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

replies(2): >>45117471 #>>45117603 #
33. jfagnani ◴[] No.45117464{7}[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.
34. brazukadev ◴[] No.45117471{5}[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.
35. Muromec ◴[] No.45117603{5}[source]
The point is you mostly don't want this level of encapsulation
36. Muromec ◴[] No.45117663[source]
Another pain in the ass is the fact web components are registered globally. Good luck marrying this with npm dependency hell where two transitive dependencies both import a button.

The good part of react and friends is it's just javascript and the class is imported and referenced normally, not with a weak string-binding-through-registry kind of way.

Now add types to the mix and shadow dom and it brings constant problems without any upside.

37. Muromec ◴[] No.45117764{3}[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.

38. ulrischa ◴[] No.45118308[source]
We used to put a link to the overall stylesheet in the webcomponents. That works pretty good
39. skybrian ◴[] No.45118715[source]
Aren’t a lot of components leaf nodes, with no slots? Does the shadow dom have any benefits for them?
40. troupo ◴[] No.45120190{4}[source]
The irony is that the original vision of web components was what you wanted. See Alex Russels "a vision for the Future": https://web.archive.org/web/20121119184816/https://fronteers...

--- start quote ---

I think we're stuck today in a little bit of a rut of extensibility. We wind up leaning on JavaScript to get things, because it is the Turning complete language in our environment. It is the only thing that can give us an answer when CSS and HTML fail us. So we wind up piling ourselves into the JavaScript boat. We keep piling into the JavaScript boat.

Bruce yesterday brought up the great example of an empty body tag, and sort of this pathological case of piling yourself into the JavaScript boat, where you wind up then having to go recreate all of the stuff that the browser was going to do more or less for you if you'd sent markup down the wire in order to get back to the same value that was going to be provided to you if you'd done it in markup. But you did it for a good reason. Gmail has an empty body tag, not because it's stupid. Gmail does that because that's how you can actually deliver the functionality of Gmail in a way that's both meaningful and reliable and maintainable. You wind up putting all of your bets, all of your eggs, into the JavaScript basket.

....

They're the sorts of things that you use when the semantic that you're trying to express is so far away from what HTML natively has a semantic for, that you're willing to go and be completely self served for it. Taking on for yourself accessibility, UI, UX, internationalization, localization, performance, theme ability; all of this stuff is mostly taken care of for you by HTML.

--- end quote ---

14 years later, web components depend on JS to:

- participate in forms

- solve accessibility issues (not yet, but coming through a yet another JS-only standard)

- SSR is still mostly tied to JS and specific JS frameworks (and Declarative Shadow DOM doesn't really solve the issue because it requires you to duplicate a lot of code). See also https://ionic.io/blog/the-quest-for-ssr-with-web-components-...

- CSS modules and other imports that are moved entirely into JS

etc. etc.

-----

Slight off topic. From the same talk:

--- start quote ---

Now, we can do some of that today. We can go and look at the top million pages and figure out which JavaScript library that they're using, which features are being most heavily used, we can put those things in DOM. But is that the right place for them? It's a hard thing to figure out.

--- end quote ---

I wish they spent time figuring that out. We wouldn't have to wait a few decades for https://open-ui.org to slowly make its way into the browsers.