HTML Web Components
blog.jim-nielsen.com
blog.jim-nielsen.com
I also think having a `user-avatar` take a `src` prop makes way more sense than having to add an `img` tag inside it everywhere I use it. In that case what am I saving? What is reusable?
Vue/React/Angular don't seem like they are trying to "replace" HTML (re: "XHTML wanted to replace HTML4, but HTML5 wanted to augment it. HTML5 won.", in the "On The Web, Augmentation Wins in the Long Run" section), they are taking HTML/CSS/JS and building on top of them. If they all used canvas to render instead I might buy that argument but they don't. They absolutely push those technologies to their breaking point but it's nothing short of amazing in my book what you can accomplish with them compared to just HTML/CSS/JS and even "web components".
I was excited when Web Components were first announced but they are incredibly lackluster with no "Batteries included" and feel like they don't really help you build web _apps_ like the frameworks do. Every alternative to the big frameworks (looking at you htmlx) feel like minor syntaxic sugar for jQuery and friends which feels like a massive step backwards and completely the wrong choice for building a web app.
Yeah, the lack of concrete examples makes this feel a bit too much like a shower thought to me.
This was not a tutorial or an article on how to use Web Components.
I'm working on building exactly this resource alongside a series of posts on web components.
The Stackblitz example is quite good too.
I'll give it shot to build a super simple one with just vanilla JS without helper libraries like Lit or Stencil. I think I'd take the same approach as I would with React, and I think the biggest difference would be where the fetch gets executed. In React you'd expose a prop like "submitHandler", but here I would emit an event from the component (after whatever debounce amount) and expect the caller to attach an event listener to my custom event to perform the fetch.
In the last 10 years the only new web tech I’ve seen get traction outside of tech communities - so actual job postings etc - is vue.
Define _app_. React doesn't have batteries, it has composability. Web Components do too but you have to know how (it's a lot easier in React, just return (html)) but in Web Components, you can register your custom element and provide the functionality that you call "batteries". [1] So if you don't care about attributes and just want semantic composable things, just call it whatever you want to. <user-avatar></user-avatar>. Conceptually it's a web component that extends HTMLDivElement.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...
The benefit boils down to progressive enhancement: because an img tag has built in behavior you simply rely on default rendering behavior and provide "augmentation" as needed via your web component.
They mention not wanting to pass though all those props:
<super-slider type="range" min="0.5" max="4" step="0.1" value="2" unit="em" target=".preview h1">
We will ignore the last 2 since those are required anyway. How is `type="range"` not the default that you would just set, no attribute/prop needed? Then min/max/step/value all feel like things you could have defaults for and then, yes, pass them through. In forms I'm always pushing towards consistency, I don't want to make it easy to just set random attributes on the underlying element, it needs to be deliberate.I can believe I'm just missing something but Web Components just seem like extra work with very little gain.
Personally I think the main problem here is client side rendering to begin with, with a modern server side templating library you get a component based structure too and can abstract whatever HTML tags you want in your component before client side JavaScript.
Problem with React is that it is JavaScript first, you always begin with a JavaScript function, but in my opinion the web should be HTML first.
The article goes on to add a good little bit of JS to make everything work they way they want. They still need JS to accomplish what they want. If you turn off JS things will break in that example.
> Personally I think the main problem here is client side rendering to begin with
I mean unless you want to roundtrip for new HTML segments (aka Liveview or whatever Laravel has) you either need to have client-side rendering or duplicate your rendering logic (in something like both PHP and JS for the fast update without refreshing on each click). I'll never duplicate rendering logic again if I can help it and that means client-side render (potentially with SSR for the first render). It avoids so many bugs/issues.
> but in my opinion the web should be HTML first
This just feels dated to me. I fundamentally do not understand this desire. What do you gain from the web being just HTML? What does that even mean? With a CSR framework you are still rendering out HTML, I don't understand why some people care that the HTML was generated server side or client side. The web has moved on from being just documents, it's interactive and that provides a much better UX.
There will almost always be a roundtrip, either to fetch HTML segments or to ask for more JSON data, except for the rare cases you already have everything, because that is the nature of client-server paradigm.
By putting all your templates in the backend you can render them as a whole document or in parts in one go and send them wherever, to the browser, over Ajax or in the email. No need for buggy asynchronous SQL JOINs over HTTP and infinite state handling.
If you always start with a JavaScript function, and all that comes with that, you need a programmer to be able to create the web, but with HTML (and CSS) first you can have other categories of people do that, like designers. And combine that with a library like htmx you can then enhance that experience for interactive parts and still keep everything in the same backend template. And if it still a need for more complex interactive parts a programmer can can add that with JavaScript afterwards. That is a much better division of labour.
And it is not outdated, browser actually excel in rendering HTML documents, that is what they are designed to do, thus it will always be faster to render the HTML document as it is rather than building it on the fly.
And also the core idea of reaching for JavaScript before HTML will result in suboptimal solutions, I have seen so much unnecessary JavaScript code that could have been easily solved with a few lines of HTML. This change of perspective changes how we think and reason about a problem and therefore our solutions as well. That is why the bootstrapping of a "modern" web app has become more and more asinine.
Another problem with frameworks like React, Vue, Angular and et al have is that they have their own lifecycle and that has made the web closed and not open how it once was, closed in the sense that you can't enhance the HTML document from the outside after it been rendered, thus this leads to the assumption that the person(s) who wrote the site is also the person(s) that manages or uses it, that is a bad assumption.
What is that, exactly?
> By putting all your templates in the backend you can render them as a whole document or in parts in one go and send them wherever,
All frameworks can do that. Web Components cannot.
> If you always start with a JavaScript function, and all that comes with that, you need a programmer to be able to create the web, but with HTML (and CSS) first you can have other categories of people do that, like designers.
Web components quite literally don't work without Javascript. And they need Javascript to be able to do trivial things like form participation.
Component rendered before client side JavaScript.
> Web components quite literally don't work without Javascript.
That is why I'm not using them.
It is enough for a bazillion of online services, that without requiring a beyond insanely complex and massive web engine from Big Tech. basic HTML forms can do wonders.
Of course, you can have a full blown Big Tech web app, but don't forget to have a interop portal with noscript/basic (x)html browsers to avoid, at least for critical online services, Big Tech lock-in and unreasonable exit cost.
That said, it may be a good idea to be able to drive the display or not of <table> rules with the default styling (css or hardcoded) from the 2D semantic HTML document attributes (I should check the hardcoded style of links and lynx for <table> rules).
(I am not talking about the abomination of the "semantic" web we had a decade ago)
Of course, it is a trade-off, bells-and-whistles from rich GUIs are sexy, but the technical cost of such bells-and-whistles in a web context is grostesquely and absurdely unbalanced compared to what can be achieved with simple and consistent noscript/basic (x)html portals for any pertinent goal of a bazillions of online services.
The problem often lies with the client tantrums.
I was more talking about critical online services which have a duty of interop with Small Tech and must not force users into Big Tech engines only, that to keep the door open to alternatives of reasonable "size", and at the same time to lower significantly exit costs.
But that's smashing open doors, most are aware of those issues here on HN. The real issue is implementation: it has to happen in a regulatory framework, laws dealing with discrimination, and my lawer has been looking into other legal leverages (yeah, I have an open conflict with my administration). The regulatory framework is here, but lobby-ied heavily by Big Tech, making it ineffective and pointless.
A bit like what they have in the US with the "utilities" which then have much more regulatory duties than "non utilities". You also have anti-trust stuff: dominant corpos are much more tied to regulatory constraints, that to let alternatives to be viable (well, that does not seems to work very well in the US). In my country, anti-trust ultra-aggressive regulations did wonders in the telecom industry.
You can still have a web app with a rich GUI, an anonymous simple and stable in time public HTTP-based middleware protocol (which allows to develop Big Tech independent rich GUIs), etc, until the core functions are provided to noscript/basic (x)html browsers (if one thing must work, it is this one).
I actually have zero Web Component experience so I'm not sure if I'm following best practices there, but I was able to get that working pretty quick
True
>which feels like a massive step backwards and completely the wrong choice for building a web app.
Why?
I mean, I'd agree if by 'web-app' you mean something like google-sheets.
But I believe this whole "anti-react" movement isn't talking about such usecases, but rather against defaulting frameworks and building using them 'from the ground up', where trully all the website actually need is the "sparkling of interactivity on top"
We absolutely don't have shared language for these things and we aren't always talking about the same things. The thing is there are just vanishingly few places where you only need a "sparkling of interactivity on top". Yes your blog probably doesn't need a full framework, nor does your news site (which is just a blog++) or your marketing web page. But so many other things really do or things break down quickly. Also what your web site needs today might not cover what it needs tomorrow. I've seen a number of "web admin"/backend control panels (customer-facing for config) start simple then grow until they start to collapse under their own weight with just added jQuery as needed. Sure, at the start, htmlx/jQuery might cover all you need but soon you are building custom UI to represent business logic/ideas and managing with that gets very unwieldy. The people that say "all you need is the built-in HTML elements" are living in a fantasy land, try using the default date/time picker and get back to me.
I'm sure there are things I'd agree with the anti-react crowd on (places you don't need a framework) but all their examples are incredibly contrived and feel like the "TODO app examples" you often see for frameworks or learning a language. They don't even scratch the surface of what's needed for complicated apps, they are great to show off the simple things but it seems like the anti-react/anti-framework crowd thinks those simple examples are all you need and that's just silly.
At the end of the day I'll admit I reach for a framework earlier than I absolutely need it and that's because I've built 10's and 10's of sites (web apps) from the ground up and eventually you either use a framework or you end up creating a shitty version of one. So yeah, day 1 I might not need Vue but day 100 I'm sure glad I have all of Vue to build on.
Some projects require 1% of a framework, others require 98%, but the majority are in a range between 25% and 75% which currently need you to re-architect for a total perfusion of React or a competitor.
I think it's more likely to see some kind of WASM-based replacement take off rather than browsers get their act together. That's not to say browsers aren't improving, they absolutely are, but when it comes to competing with the existing frameworks the only answer so far has been Web Components and it was very lackluster IMHO.
Sveltekit (its official fullstack framework) even encourages building apps that fall back gracefully for users with JS disabled.
Of course, none of that is to say that you can’t build bloated, badly performing apps in Svelte. Just that you *can* have the best of both worlds, even for simple/static sites.
[1] There are very few monoliths among the frameworks these days, and apart from React and Angular [2] most aim for rather small bundle sizes
[2] Out if the blue Angular just released version 17 with all the goodies you'd expect from a framework in 2023
They mostly publish static content: alerts, updates, reports, etc…
At most they might have a single page somewhere for submitting a payment or a simple form.
But because of this JS framework by default policy all their apps end up with extra complexity, extra build steps, and an awful amount of dependency maintenance.
Most of their sites could have been static HTML files on disk.
Doesn't even make sense to me why anybody uses them.
You cant audit static sites (ones thing I don't like about having traditional linked libraries).
Why can’t you audit a static site? Seems very straight forward. We already audit static sites for accessibility (503 compliance).
Any resources you can point to? Seems like it would be a worthy effort to make other tools compliant.
Definitely something I want to learn about.
I'll never say Vue/React/Angular are "light" and I'll fully admit we give up some performance for DX (and UX) but it's a tradeoff I think is worth it (I understand if you don't agree).
In the same vein, I know cross-platform frameworks like Ionic/Quasar are nowhere near as good as native apps. That said the skill set you need (and dedication to actually embracing the platform idiosyncrasies) to make _good_ native apps is not cheap or easy. Cross-platform apps might not fit in as well and might be heavier but they allow fewer people to do more with less. Heck, I have a side-business that relies _heavily_ on apps and it would not exist if I couldn't write them in HTML/JS/CSS as much as that makes some people's stomachs turn.
I disagree, at least around here. Frontend developers with react/angular experience are a hot commodity and really hard to hire, yet just about anyone from any tech tech can knock out html and some minimal css.
But also, you can mix things togheter. You can just use react based app 'embeded' into mpa for when you need that heavy lifting, and the same keep the content part of your app simple.
"But why would i do that, if i'd already use react for some parts, why not every where".
Becuase then it leads to abominations like reddit or facebook, where websites that are basically glorified text forums will use gigabytes of memory, have terrible UX, be slow and will crash your browser if you leave them open for too long.
Stringly typed logic and CSS / JS somewhere miles away in directory structure making it very hard to reason about.
I very much prefer sticking to small, composable, encapsulated, actual components made in React or sth similar.
To have even more HTML soup? No thanks. Luckily I live in a world of better DX. With styled-components my CSS primitives are typechecked. Hell even with SCSS and CSS modules I have more sane and IDE supported experience.
And yet, despite everything facebook is doing, the most (and only) reliable way to load new comments under the post is to force refresh entire site. Except it's not easy anymore, because facebook tries to be SPA.
So we gave up simple and reliable solutions in favour of over engineering that doesn't even work. And all that for no good reason, other then being trendy and having an SPA
At some point quantitative change achieves a qualitative effect. I would think Facebook or LinkedIn or Twitter have all reached that qualitative effect to change from being just a discussion forum.
However qualitatively the social functions of these apps present an extra functionality missing from traditional discussion forums. Being able to track users, notifications of the users updates, blocking certain users from being in the message - which is a traditional messaging function not found in discussion forums. Suggestions of people or subjects to follow given on what you have done in the past, weighted based on various algorithms to determine how recent your past activity was and what your current interests seem to be.. I'm sure you could think of a load of other functions that are not traditional discussion forum functionalities.
In the parent coment alone I emphasized that I acknowledge that Facebook as a whole provides more then just a forum, but it's core content inherently doesn't differ much from being one.
Moreover, functionality like notifications or suggestions are inherently server generated, as such they don't require content itself to be served in specific way.
- the social graph underlying every post and content producer (one of the reasons FB introduced graphql)
- the recommendation and advertising algos that are interdependent on the content feed
- the realtime “fire hose” nature of the feed integrating a huge number of disparate data sources
Again I don’t like FB the app and I’m not on it. But even its core product is vastly more complex than a forum.
FWIW I’ve developed social networks and forums professionally; social networks are inherently more interactive. My first real exposure to front end dev was when I worked on a social network. If I had to build the same webapp today there is zero consideration of writing it as a backend rendered application or restricting to only progressive enhancement. It would only put off the inevitable migration to real FE tech.
What specific aspects of facebook's comment section under post make it that json response is so much better then a html one?
Building my first web application in react currently and this resonated with me on such a deep level.
It is a fancy HTML templating library first and foremost and you should use it when you need HTML templates, which means you that can use as little or as much of it as you want.
I’ve built mostly static pages with React loaded and embedded into parts of the page. The webpages would function without JavaScript enabled.
I would say it's precisely the opposite.
Say 97% of work done by web pages and web apps in practice boils down to "render some data available on the server as HTML, then show it to the user". For these cases, putting what amounts to an entire GUI framework written in Javascript on the frontend is massive, bandwidth-sucking, performance-killing overkill.
There are absolutely exceptions. Google Sheets exists. But your project is probably not Google Sheets.
I swear the people writing these comments aren’t working in web development?
IME there’s a crazy amount of strawmanning that goes on with these “anti-react” technologies/cults. Yes of course your html and css static site doesn’t need react. But most of us who are actual software devs/engineers aren’t working on static websites like that!
class superSlider extends HTMLElement {
connectedCallback() {
let targetEl = document.querySelector(this.getAttribute('target'));
let unit = this.getAttribute('unit');
let slider = this.querySelector('input[type="range"]');
}
}
customElements.define("super-slider",superSlider);
For a more sophisticated example with scss, jsx/tsx and ES20.. you could take a look at https://github.com/cyco/WebFunMy personal problem with these "native" components is, that the shadow DOM is pretty restricted compared to component frameworks like React, Vue or Svelte.
The shadow DOM provides two things:
- style encapsulation (as well as `id` attributes)
- ability to use `<slot>` for templating
You should use it if you require one of the above or both.
Baloney if you ask me.
I guess user-avatar could define a template that includes styles and slots to turn the image into a round image and maybe add some caption and link to it. But that would still require JS to print the template.content.
I wish this weren't so, but it perfectly describes my experience with every single web technology. JavaScript, DOM, Canvas, Web Audio... they all remind me of this quote:
"Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy." -Alan Perlis
I used a PDF library that didn't automatically flow text onto the page. You had to do it yourself. Line by line. Page by page. So, I wrote a few routines to do it. Maybe 50 lines? And I'm just like... this PDF library is twenty eight thousand lines lines long... and they couldn't have included those fifty?! Why!
Meanwhile, a browser is 10-20 MILLION lines of code, and ... I originally ranted for several pages, but I'll just go and say that I never want to see the string "undefinedundefinedundefined" show up during runtime (and that this is 100% realistic and achievable in a dynamic language, without type annotations).
No need to break existing software. "use strict" was a great idea. Let's do "use sane"!
Achievable by just removing automatic type coercion. Throw errors instead.
Would need to be feature flagged for backwards compatiability.
I always thought JS needed static types to fix the insanity until I tried Python and realized that almost all the insane BS I get in JS are all runtime errors in Python.
There's a very good case to be made for reducing runtime errors, but it's a hell of a good start to at least have them!
Rather than what we have now, which is "assume the programmer is a beginner, who also never makes mistakes", and "given nonsensical commands, just do nonsense, and propagate garbage data throughout the entire program".
Building an entire web app out of Javascript has been an incredibly dumb idea, and some ecosystems are trying to return us to the roots: most of the heavy lifting is done server-side, and JS is a sprinkle of interactivity on top, like the golden age of jQuery.
Before you bite my head off telling me about apps that necessarily have to be SPAs, how many apps are people using React for when a modern server-side framework would do (i.e. Phoenix Live View)?
Have you used htmx? Since it doesn't solve the same problem jquery did (UX for client side JS), the accusation is misplaced. htmx is (primarily) a way of avoiding writing JS by extending the server-side rendered html paradigm to partial pages instead of full page re-loads.
htmx shines to add dynamic behaviour on some pages, but is not appropriate to replace a medium-sized SPA in my opinion.
The author's dichotomy could be seen as unnecessarily divisive by creating an artificial distinction and suggesting only one must be chosen. It also seems not to reflect an underlying technical reality nor suggested best practice. In reality, both React and custom elements can enable either style, and the choice should depend on what's most appropriate for the situation.
Not only can both frameworks do both approaches, they can do them at the same time! You can have a wrapper style elements that also takes props. A window-box that provides diverse content with an OS-style draggable-window capability is a good example.
As to the author's suggestion that HTML components (which appear nevertheless to still require JavaScript) are better, and prop-style is to worse, in general, I'll have to think more about it. I may have underappreciated the light DOM style in my creation of Hyphen: https://github.com/00000o1/-
Instead of focusing on slots for templating (which you can still use if you want) in Hyphen, I made templates easy with JS template literals, because it's not always just elements you may want to insert, but rather class names, attributes, and so on. Check it out if you are interested in new approaches to custom elements! It's only 3K and less than 300 lines, aiming to provide maximal utility with minimal code.
The `details-utils` component enhances the behavior of the built-in HTML `detail` component. If for any reason you have JavaScript disabled, then using a web component like this would be just fine because the `detail` component would continue to behave like it always does. If you have JS enabled (or it's finished downloading) then you have an enhanced version of it that has features like collapsing when you click outside of it, etc. That's the part that's reusable when used like this.
That web component from the creator of 11ty is what made the point made in the article click for me. When I first started looking at web components I was like, "this still requires JavaScript and doesn't work without it," and that was the same point Rich Harris made in this article: https://dev.to/richharris/why-i-don-t-use-web-components-2ci...
https://meyerweb.com/eric/thoughts/2023/11/01/blinded-by-the... - "So there you have it: a few thousand words on my journey through coming to understand and work with these fully-Light-DOM web components, otherwise known as custom elements. Now all they need is a catchy name, so we can draw more people to the Light Side of the Web."
https://adactio.com/journal/20618 then suggests the catchy name.
Sure you can get re-usable components. But are you going to pull in a re-usable web component that might use say Vue underneath when you use React? It just doesn't make any sense.
The best example is a multi-select box, or a searchable select box with autocomplete (what W3 calls the combobox pattern https://www.w3.org/WAI/ARIA/apg/patterns/combobox/) which in jquery was usually via https://select2.org/
For example, on my company website there's a timezone select box with 151 options. Asking a user to scroll through 100+ options is a big ask vs typing a few characters and hitting enter. There really is no static server-side way to solve this problem (I tried hard to think of one)... without creating a multi-page Wizard for what should be a single field on a larger form.
If you're building a SaaS product there are many UI requirements that demand high-interactivity and and there's really no better mainstream solution atm than static-first sites with small "islands" of React/Vue/etc components (ideally with hydration).
People still abuse React/Vue of course and the trend is 100% moving back to "mostly static" rather than slow SPAs but IMO JS-powered components are not never going away unless browsers start offering a broad selection of built-in complex web components like comboboxes, datepickers, tooltips, etc.
You maybe don't get full control over the rendering style of it, but it's a still significantly more usable than the Angular Material autocompletes.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/da...
It's a shame clicking on it doesn't show the options like a select box though.
> Recommended values in types text, search, url, tel, email and number, are displayed in a drop-down menu when user clicks or double-clicks on the control.
https://adrianroselli.com/2023/06/under-engineered-comboboxe...
> People still abuse React/Vue of course and the trend is 100% moving back to "mostly static" rather than slow SPAs
I'm not seeing this at all, in fact I can't remember the last React project I worked on that wasn't a full blown SPA. I don't see anyone starting or advocating for static sites with islands unless they're using a framework like Astro or something.
Do you have any example sites or codebases using this approach?
> const app = h('h1', null, 'Hello World!');
With Web Components no build step is required and you're still able to intermix HTML with JS just like JSX. See the code below this section: https://github.com/kennyfrc/cami.js#key-concepts--api
It is not completely the same, but far better than that h function madness.
Meanwhile, "use the platform":
- all form components written before form participation landed in browsers are broken
- all web components written before cross-root ARIA (not even a spec yet) are potentially broken due to shadow DOM
- ... you may continue this list at your own leisure ...
The issue is just some sort of "front end bad" feeling at this point, imo. It's like some people think web components are the answer to the popular perception of the frontend being a mess of yearly novelties. When again, you can just use react and could have done so for a decade now.
I wonder what minimal solutions to state management and routing might look like in Hyphen: https://github.com/00000o1/-
So much of the beauty & elegance of the web was how declarative everything is, as that grants such observability & malleability. Shadow dom felt such an enterprise desire, to build much higher encapsulation walls, to layer in so much certainty, and that never felt like a goal I shared.
This article shows how light dom work can compose. I want to see light dom advocacy go further. It always seemed clear to me a web component/custom element could and should just self-modify the dom inside of it, move children around, build new content. Another example in the comments talks about maybe the user avatar element adding a div with the users name... Maybe the page or framework adds the icon, and the custom element then inserts that name, or that name and some aesthetic embellishment.
I guess my one concern with light dom / html web components is it seems like there have been - in some cases - some good performance wins from shadow dom. This wouldn't change what I go for unless I was desperate, but as a dev, in my head I see how shadow dom can scope down and reduce the number of elements that have to be traversed for a css specifier. and I want that win to be available somehow to me.
Really elating to see a lighter take on custom elements / web components. Thanks for the great links Simon!
Not a full stop; SSR means they could render before client-side JS.
The example is a bit too simple to make the author's point IMO. A web component that handles changes to state would be a better comparison, and make for a better argument.
Arguably they might be less optimisable than regular web frameworks, as they make it difficult to coordinate between different components on the page.
Good load order and only loading in the content and JS above the fold initially helps a ton.
JS frameworks are huge and I am still saddened that proper tree shaking and optimization got left by the way side in how the modern web has evolved. I worked with google closure in advanced modes and the closure components for a few years and the compiler was absolutely astounding (and the components designed with the compiler in mind) in code splitting, tree shaking and minimization.
You want to have the tags and content appear in the web component (not rendered by JS) which makes it easily and immediately available to crawlers.
Hydration solutions exist but are usually worse and come with surprising tradeoffs and harm composabilitiy.
https://github.com/kennyfrc/cami.js
> No Build Steps, No Client-Side Router, No JSX, No Shadow DOM. We want you to build an MPA, with mainly HTML/CSS, and return HTML responses instead of JSON. Then add interactivity as needed.
> Declarative templates with lit-html. Supports event handling, attribute binding, composability, caching, and expressions.
https://github.com/codewithkyle/supercomponent/blob/master/s...
ctrl+f htmx
"For folks who have an existing server-rendered application, you can use Cami to add interactivactivity to your application, along with other MPA-oriented libraries like HTMX, Unpoly, Turbo, or TwinSpark."
You don't really make "a web component", what you make is a Custom Element, which might use a Shadow DOM, and might use an HTML template. Three things of which the most important one is the custom element.
With the core concept being that you're just making "more HTML elements", everything you can do with those, including which attributes and JS API they support, is up to you, and the way you put them on a page, the way you interact with them, the way you listen for events on them, etc. etc. is the exact same as any other HTML element. If you known how to write web pages the "old school" way, then you already know how to use custom elements. You just need to learn how to declare them.
The only thing holding web components back seems to be HTML Modules; being able to link to a .html file instead of a .js file to import a web component. Because of this if you want to use templates or anything more complicated you need to do the ugly inject of .innerHtml = `<tag soup>...`, which I thought would be a problem but the IDE parses the template string very nicely. It would be great to make a component in HTML and any javascript you would put in a <script> tag. It seems like there a lot of bureaucracy involved in getting HTML Modules out the door since its been eight years.
https://github.com/WICG/webcomponents/blob/gh-pages/proposal...
And no, it's not the only thing holding web components back
Maybe the author has worked in different React codebases than I have, but in my experience, we use built-in browser functionality unless we have a reason not to. Maybe I've just been lucky?
[0]: https://react.dev/reference/react-dom/components/common#reac...
React (rendering in the browser, not server side): Page Load -> Component Load
vs.
Web Component Page Load -> Default Render -> Component Load
So if someone has JS disabled they would still see SOMETHING for the web component vs. nothing in React. And with JS they could get to some further render state.
The point is that the flavor "HTML Web Component" does not rely on JS to start rendering, unlike React.
A popular app that some web developers here may use day-to-day recently is Figma, which uses WebGL for rendering.
A variation could be the rendering of a partial UI whilst you then fetch data client-side. Even in this case the web component has the advantage as no JS is needed to render the initial UI.
<special-image>
<img src="/example.png" />
</special-image>This image will render before the JS is executed, so you've got no blockers and a perfectly fine fallback, then with the web component you enhance your image with whatever JS you want.
This is my experience too, and this philosophy have made my web projects last a long time with minimal maintenance and dependencies.
I made a video player web component that could take in various inputs, with a torrent file being the most complex of them. I was then able to port it to Vue/React with StencilJS [0] (although it was good to go without). Just drop the `<awesome-player src="torrentOrVideoFile"... ></awesome-player>` along w/ its exported class from `awesomePlayer.js` and you have yourself a copy/paste HTML5 video player that plays torrents!
I also strongly suggest your web component attempt to mimic existing HTML elements, when possible, such as how I used `src` because `<video>` does. That way the consumer doesn't have to RTFM to interact with it.
Also disagree with the side note that XHTML failed because it didn't augment HTML. IMHO it failed because if forced the applications to be completely valid and it put the validation on the client/browser. If you'd really used real XHTML a small error in the markup would've crashed your page. So we all validated our XHTML to be future ready, but it was always utopia that a business would risk crashing their, well, business because a p tag was not properly closed.
> Svelte components can also be compiled to custom elements (aka web components) using the customElement: true compiler option.
https://svelte.dev/docs/custom-elements-api
This would negate the "vendor lock-in" arguments and allow Svelte for component development but web component for consumption and use. Best of both worlds. All the DX advantages of Svelte over web components without sacrificing interoperability.
> <img src="https://example.com/path/to/img.jpg" alt="..." />
> </user-avatar>
I thought the standard way to do it is:
<img is="user-avatar" src="https://example.com/path/to/img.jpg" alt="..." />
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...
<user-avatar>
<img slot="image" src="...">
<div slot="name">Bob Bobson</div>
</user-avatar>
Edit: I'm meaning the attributes being longer than what the tags are denoting.
That said, I think the author's bigger point was that augmenting, rather than replacing/abstracting away basic web elements will win out long-term. Some degree nastier-looking coupling is a worthwhile trade over more opaquely-operating render libraries. I suspect augmented web components fail more gracefully too.
If you're looking for a middle-ground between React and Web Components, check out Joystick [1]. I designed it to take a React v1 approach to ergonomics but you write your components with vanilla HTML, CSS, and JavaScript (no attribute hacks or new syntax to learn—if it's on MDN, it will work in Joystick).
https://github.com/Saasufy/chat-app/blob/main/index.html#L23...
You can try the app here (if you have a GitHub account): https://saasufy.github.io/chat-app/
The backend is serverless built using Saasufy.com - The platform/startup I'm working on currently: https://saasufy.com/
An effective approach I've found is to create components which consume slotted <template> elements to produce HTML that can be fully customized and injected with data they loaded from a back end. This allows you to create components which are declaratively bound to specific back end resources.
Except all the custom code in saasufy-components
I'd like to like them, but, no.
The encapsulation coming with shadow DOM can be done in other ways (CSS modules) so light DOM seems a like saner approach... but then you lose the slots and they are must have for any composability.
Render your react components on the server and send them over the wire as plain html. no client side javascript required — full stop.
Moving the render off the client is nice, but removing the prerender altogether is something much cooler.
Html templating
Rendering react on the server isn't some magical hip technology. It's just a different template framework. I'm not pretending this is anything special or fancy.
Doesn't this then require the server to be written in Javascript as well?
<template type=component name="user-avatar" parameters="[src,alt]"> <img src="{src}" alt="{alt}"/> </template>
From <user-avatar> we can give styles to <img>
<user-avatar> <img src="https://example.com/path/to/img.jpg" alt="..." /> </user-avatar>
but not anymore when its below <picture>
<user-avatar> <picture> <img src="https://example.com/path/to/img.jpg" alt="..." /> </picture> </user-avatar>
I definitely feel like I'm doing it wrong, but all the guidance I see doesn't help - they're all very "hello world" examples that don't get into the difficult stuff.
I want to believe... but reality is stacked against HTML web components. I'm just going to stick to HTML and leave the HTML with dashes to others.
I can’t link you to them here without blowing my cover, but honestly I love working with web components, and being able to do it natively rather than propped up by a mound of JavaScript feels good.
It's just as native as any other framework under the sun.
Because they don't exist. "HTML web components" are just HTML, and you don't need components for them.
Web Components are useless without Javascript.
The website itself also built with web component
[1] https://www.abeautifulsite.net/posts/flash-of-undefined-cust...
Here is my blog post about custom HTML Elements. It covers state changes, etc.
P.S., I am looking for a Front End project, preferably writing vanilla JS. My email is on the page.
Funny, huh.
it is a pretty intuitive term - interoperable building blocks in areas that suffered from fragmentation - but isn't really part of the lexicon by the lexicon gods
HTML web component is NOT a function.
You don't just compare those things, they work and compose differently.
I would rather combine them: A html web component renderer for React.
function Dog() {}
var dog = new Dog();
Hey look classes are actually functions, now you can compare them, have at it.Web components don't address this on their own, which is why a lot of libraries still exist that build on top of them.
I wouldn't say that React's component model is being ported to the browser, just that a component model is being implemented in the browser, independent of and different than React.
Microsoft ActiveX Dynamic HTML Behavior Components (HTC files, introduced in IE5, after DHTML finally started working well) allowed you to augment HTML in the same way, and that's very old technology (circa 1999 or so) compared to React.
https://news.ycombinator.com/item?id=27405137
>[...] At the time that NSAPI came around, JavaScript wasn't really much of a thing, and DHTML didn't exist, so not many people would have seriously thought of actually writing practical browser extensions in it. JavaScript was first thought of more as a way to wire together plugins, not implement them. You were supposed to use Java for that. To that end, Netscape developed LiveConnect.
>Microsoft eventually came out with "ActiveX Behavior Components" aka "Dynamic HTML (DHTML) Behaviors" aka "HTML Components (HTCs)" that enabled you to implement ActiveX controls with COM interfaces in all their glory and splendor, entirely in Visual Basic Script, JavsScript, or any other language supporting the "IScriptingEngine" plug-in interface, plus some XML. So you could plug in any scripting language engine, then write plug-ins in that language! (Easier said than done, though: it involved tons of OLE/COM plumbing and dynamic data type wrangling. But there were scripting engines for many popular scripting languages, like Python.) [...]
HTML Components:
https://en.wikipedia.org/wiki/HTML_Components
HTC Reference:
https://learn.microsoft.com/en-us/previous-versions/ms531018...
I used them to implement nested piemenu components in a way that let you easily augment them with html in the browser (which was the wall I'd hit with OLE, not being able to easily use an animated gif or html table as a pie menu item, for example, having to draw everything myself with Win32), so you could embed snippets of HTML to define the menu background, center, items, and dynamic feedback.
That worked nicely in conjunction with XSLT to transform XML models into HTML pages with embedded trees of HTML components.
For example, the Punkemon Pie Menus used an XML database of Punkeland regions and Punkemon characters to make a tree of nested pie menus.
JavaScript Pie Menus - Punkemon Pie Menus:
https://youtu.be/R5k4gJK-aWw?t=177
Pie Menu ActiveX Behavior Control (htc file as text):
https://donhopkins.com/home/PieMenu/piemenu.htc.txt
Punkemon Pie Menus XML Database (xml file as text):
https://donhopkins.com/home/PieMenu/punkemon.xml.txt
XSL Style Sheet (xsl file as text):
https://donhopkins.com/home/PieMenu/punkemon.xsl.txt
For example the XSLT transforms the XML Punkemon database into HTML with embedded nested <piemenu> <item> and arbitrary html, like a table inside one of the items to make a gigantic pie menu item at the bottom, whose purpose is more like an info panel than a menu item, just showing you some information about the magnified animated gif of the character in the top item.
ActiveX Pie Menus that "hit the wall" (discussion near end of video):
https://www.youtube.com/watch?v=nnC8x9x3Xag
>Well, I ran into a wall of complexity with this ActiveX control, and I wanted to be able to have as the menu items animated gifs, mpeg movies, fonts with nice attributes, and things like that. The first thought was "well let's just put a web browser in every item!", but that was a little heavy-handed. So instead I put the pie menus into the web browser as dynamic HTML components, which I'll show next.
All this stuff I explained in the video is incredibly obvious now, but it seemed really cool at the time in 2001, and it was a hell of a lot better and more web-centric than binary OLE/ActiveX controls. (Pardon my unabashed XML and Microsoft technology advocacy, but it really was a step up from what came before it, and you couldn't do anything remotely similar in Java!)
But it illustrates that the idea of augmenting and embedding html in components like that goes way back, and that HTML Web Components were obviously influenced by Microsoft ActiveX Behavior Controls more than they were React.
JavaScript Pie Menus: example of augmenting neste piemenu components with html:
https://youtu.be/R5k4gJK-aWw?t=339
Transcript:
Now the really convenient thing for user interface designers is that the way these pie menus are specified in XML markup language.
This test pie menu has eight items here, and North has a sub menu with four items. Now that map's very nicely into an XML tree. It has a piemenu element, and that has a name and ID.
The neat things is that you can put arbitrary HTML inside of the XML, and that is just copied and just dumped right into the middle of the menu to make it look any way you want. And then the menu, this pie menu item, contains, besides this stuff to display in the middle an item, an item.
It contains eight items, and this item's name is north, and that's its name to the program, which could be different, and that's what is displayed to the user here. Now it contains the sub piemenu, which is the North menu, and has even more.
You can see how you can intersperse XML and HTML to specify all this that you need to describe for the pie menu.
One of the really great advantages of using XML for the piemenu is that there are many ways to generate XML and many things that are represented by XML that you might want to make and then use for. In the case of the punkemon pie menus I really didn't want to make all those pie menus directly.
So maybe I'm making a card game and I have this XML file that I use to print all the cards and maybe do the online game and everything. I've defined the markup language for punkemon cards. There's the punkeverse contains punkeland where they live, and that contains a bunch of punkemons.
Now all these give information that is needed to make the menu for that. It's an application specific markup style, but it has information for menus in it. Basically all this gets translated into all this very automatically by an XSL stylesheet.
That's a macro language for XML that takes the nice clean to the point punkemon xml file and then transforms it into a piemenu tree and a web page that pops that pie menu up.
punkemon.xml:
https://donhopkins.com/home/PieMenu/punkemon.xml.txt
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="punkemon.xsl" ?>
<punkeverse>
<punkeland
name="Rave Caves"
itemradius="60"
pieradius="100">
<punkemon
name="Candibi"
foundin="Rave Caves"
attacks="Disturbing Cuteness, Pacifier attack"
likes="Candy, Stuffed Animals, Loops"
dislikes="Ambient music, spankings, bed-time"
creator=""
url="http://www.gothic.net/~luvcraft/punkemon/rave/candibi.html"
image="Punkemon/candibi.gif">
<description>
The youngest and perkiest denizens of the Rave Caves, Candibis
spend much of their time spinning around in circles with one
hand high in the air and the other hand tightly clutching a
large stuffed animal. Naturally shy, these cuddly creatures
can often be enticed into a Punkeball with large amounts of
candy, especially if the candy comes in perforated sheets."
</description>
</punkemon> [...]
The header of the punkemon.xml file says "hey this is my stylesheet, if you
want to display me, run me through this style sheet!"
And what that style sheet does is expand to a web page with a title
that says what it is.punkemon.xsl:
https://donhopkins.com/home/PieMenu/punkemon.xsl.txt
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Punkemon Pie Menus</TITLE>
</HEAD>
<BODY>
<DIV ID="Barf"></DIV>
<DIV STYLE="width=100%;height=80%;behavior:url(piemenu.htc)"
onchange="ChangePunkemon(event)">
<CENTER>
<H1>Punkemon Pie Menus!</H1>
<IMG SRC="Punkemon/island.jpg"/>
</CENTER>
<XML>
<piemenu
id="root"
fixedradius="90"
centermargin="50"
centerbackground="white"
itemnormalbackground="white"
itemselectedbackground="gray">
<html>
Punkemon<BR/>
Pie Menus
</html>
<xsl:for-each select="*/punkeland"> [...]
And then, the nice part is, this
is how a web designer puts the pie menu on the page.
You make a div, which is like just a section.
And I'm giving it a width and height, and I give
it a behavior.The behavior attaches this JavaScript code to it and allows it to receive input events and translate them to a higher level semantics and then send these output events like the pie menu changed, and it's going to call my JavaScript function that's on this web page to handle it.
Now this div is the thing that's presented on the page that you click on, so it's got a little picture of the island there. Inside the div besides its presentation is an XML data island, which is just embedded XML that instead of being displayed on the page is just data that can be referred to.
The pie menu looks in there, finds the XML, pulls out the pie menu definition in it, and uses it. You can pack these things nicely together. You can also point to another file that contains the pie menus externally. But in this case we're going to have them inline.
The Punkemon piemenu contains the words "Punkemon Pie Menus". And then it uses the XSL macro language to loop over all of the punkelands, making items for each one of them. And that item is made by extracting fields from that punkeland, and just sticking them into HTML as either properties or content.
You can get the value of the name of this guy and stick it into that guy, and put a bold marker around it, and make a div. This is just a bunch of nested loops that loops over the database and renders it out as dynamic HTML embedded in a piemenu tree embedded in a web page.
And it works! That's what you're seeing over here.
There's a lot of other really neat applications of automatically generating the piemenus or any other kind of user interface from an XML specification, that could also be used for a lot of other things. And you're just describing your data in one place, and then algorithmically rendering it out to all sorts of other things.
I am not a React, Vue (and friends dev) at all. Heck, I haven't done front-end or full stack for a long time now.
However, taking React as an example, where does it not encourage composability?
I like Web Components. I even spent the last couple of weeks playing only with the vanilla APIs (no Lit, etc.) just to see what is like:
https://lpedrosa.github.io/blog/web-components-part-3/
https://github.com/lpedrosa/webcomponents-blog-examples
Like many other people have pointed out in this post, it is great that you can leverage the platform. All the things you will learn e.g. DOM APIs, native elements and events, etc., are things you can carry over to React and Vue.
However, I believe articles like this fail to acknowledge the contribution React and friends brought to developer experience.
Building complex desktop like UIs was no longer impossible to maintain. You can easily make components and compose them, customise them, etc.
The general complaint is more around "you don't need Next.js" to build a news/marketing/blog website. The pendulum is swinging, especially with things like HTMX gaining traction.
IMO, people do it because:
- It's easier to hire developers that know the framework du jour
- Custom Elements are very flexible, so it's hard to enforce a particular style
- There aren't enough examples of people using vanilla Web Components (and I mean vanilla, not Lit and friends), so why use a web component framework when I can use a react based one?
Write more about how we can combine things like Custom Elements and "traditional" server side templating.
Write more about how a native element reacts to changes to its attributes or how it communicates user interaction and how that helps building a good custom element.
Or how building a good custom element is similar to building a good React component, and where it differs.
Antagonising existing knowledge or even the status quo is not constructive, and leads to poor discussions e.g. "Web Components is a failed technology" or articles like OP
<html>
<tag>
<my_tag $message="Hello, world!">
<script>
alert($message);
setTimeout(function () { alert("Boop!"); }, 10000);
</script>
<img src="my_image.png"/>
<p>$message</p>
</my_tag>
</tag>
<tag src="my_other_tag.html"/>
<body>
<!-- shows "Hello, world!" -->
<my_tag/>
<!-- shows "Hello, override!" -->
<my_tag message="Hello, override!"/>
</body>
</html>
By default, the browser would allow setTimeout(), so the user would see alerts showing after 10 seconds. But there should be a custom script.js that works like stylesheet.css that the user can set for the browser. It could have a line like quitTimeout() which would disable setTimeout() for all pages. And something like setScriptLifetime(5000) which would run Javascript for 5 seconds in this case, preventing the alerts, then only allow new scripts to run upon user action. Or even have an option like setScriptLifetime(5000, 0) where the second argument sets a lifetime for new scripts, in this case preventing all future scripts from starting.That right there would make browsers run about 1000 times faster regardless of how many tabs are open, as well as stop most of the slowdown from ads.
Maybe <tag> should be <tag tag="my_tag"> to make it inline. Or <$my_tag> so as to not confuse new tag definitions with existing tags. As they say, the devil is in the details. But I think it makes sense to nest the tag definition in case <head> or <script> tags are needed, which would maybe get installed in the parent page. And there are endless use cases for passing variables to/from tags which are beyond the scope of this comment. Probably that would happen through data tags, passing JSON or raw Javascript like for onclick="alert('Hello')" where myTag.data = 1 + 1 would be like re-rendering with <my_tag data="2">.
But if we had something like that, frontend code would end up several orders of magnitude smaller, because we'd get back to declarative interfaces with progressive enhancement, more like what Htmx is working towards.
Keep in mind that I thought of this in 1995 when I very first saw NCSA Mosaic, and was flabbergasted that html tags weren't dynamically defined this way. When Netscape copied Mosaic but failed to fix even the slightest oversights like this, I knew that the future of the web was in perile and that we'd end up with the imperative stateful mess we live with today.
> ...they can render before JavaScript
what? Because web components are written in and run on magic?
> a design of composability... composing core content with HTML and then wrapping it in a custom element that enhances its contents with additional functionality
Put aside the self-reference, that's not what composability usually means, but I guess that sounds fancy to the uninitiated
This article is a good example of this. For starters, the "one shell component" thing is kind of a red herring. There's plenty of React components that interact with children, and you can clearly make web components that also "hide all the details". So this seems to be more of a "general" good practice they want to encourage, than anything specifically tied to React or Web Components in particular.
Critically however, the whole idea of "hey, web components still look good before JavaScript!" is either intentionally obtuse or really misses the point of React -- React can have a better non-JavaScript initial render, thanks to SSR, which is significantly harder to do with Web Components. I don't really care if <user-avatar><img></user-avatar> "falls back" to some lame Web 1.0 rendering if my SSR-ed UserAvatar looks identical to the fully "active" component on first paint before any JavaScript runs. That is one of the main selling points of React and React-like systems today. You can't just ignore that completely and expect to convince anyone who's currently using that sort of system. But I understand why they don't address it, since the only real answers involve using some sort of build system with Web Components, which they've also decided to say are the worst thing ever. So their only choice is to compare non-SSR Web Components to non-SSR React Components. And, I dunno, maybe they're better than the way we did things 8 years ago when that was the case? I'd have to think hard about that purely academic question.
The funny thing is that these are often the same people that would push for as little JavaScript as possible, and yet Web Components are fundamentally tied to JavaScript. Whereas React-style components can actually generate fully static JavaScript-free pages if you want to. This sort of situation springs up a lot: Web Components go on and on about not being "shells single components", and yet React-style components make it so much easier to deal with children. You aren't forced into the ugly slot system which immediately removes the "illusion" of it being a "real" HTML component, and is easier to deal with in the catch-all case too. Not to get into another huge differentiation, but I also personally prefer a more "functional" approach of writing a single render function vs. dealing with a bunch of lifetime callbacks to track the changing states of attributes and children.
You only get two things with web components: 1. style isolation (imo everyone will switch to @scope because shadow dom is unwiedly to use, even me probably) 2. the tiny nice advantage of being able to querySelector("my-element") and being able to actually call instance methods on the thing that it gives back, directly. Dont really need that very often though, it just feels super nice.
The argument for web components is really meager and the tooling is far worse, like you said: SSR is missing, autocomplete IDE support for elements and their attributes is missing, bundling and minification is missing for the html templates and you have to do it all yourself. People are now showing off unminified js and ordering their imports manually like it's 2011 again and act like that's good. No of course that's not better than what we have. lit.dev is okay partially because I think the fact that they use web components is almost besides the point, it's just a single render function like you have with react again.
The problem with frameworks, especially web frameworks, is they reimplement many items that are standard now (shadowdom, components, storage, templating, base libraries, class/async, network/realtime etc).
DOM rendering speeds have been improved due to virtualdom but is no longer needed with shadowdom.
The web standards of today are amazing and take away the need for frameworks today: from templating to html templates [1], vanilla javascript with classes [2] and async [3] and better api access like fetch [4] and browser support for vdom with shadow dom [5], components with WebComponents [6][7], css now with lots of additions like variables [8] transitions[9]/animations[10], flex and media queries, canvas/svg/etc for interactivity, and so much more. There is little need to use frameworks except to sell books and conferences and keep developers locked in.
React for instance jumped ahead and front ran WebComponents and ShadowDOM, those are both part of the browser and standards now. The killer feature phase of React is over.
If you like the component style of other frameworks but want to use Web Components, Google Lit is quite nice. [11]
Google Lit is like a combination of HTML Web Components and React/Vue style components. The great part is it is build on Web Components underneath.
[1] https://caniuse.com/template
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[3] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[4] https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/U...
[5] https://caniuse.com/shadowdomv1
[6] https://caniuse.com/custom-elementsv1
[7] https://developer.mozilla.org/en-US/docs/Web/Web_Components
[8] https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_c...
[9] https://developer.mozilla.org/en-US/docs/Web/CSS/transition
[10] https://developer.mozilla.org/en-US/docs/Web/CSS/animation
[11] https://lit.dev/
Additionally, web standards like Web Components/templates/custom elements will always be faster at browser level.
The article from OP mentions this:
> But the unique power of web components (in the browser) is that they can render before JavaScript. React components cannot do this — full stop.
There are other reasons as well but these are the best reasons.
I think using a framework for a team isn't a bad idea, but for products and personal projects I like going custom or newer framework like Lit simply because of the web standards being less abstracted away and due to that, less need to constantly update on others schedules due to dev lock-in. There is less weight in straight standards.
If you remember React/Vue originally won due to virtualdom and being small parts that work into an existing web, but recently they have been very monolithic in that they take over the entire project. The web is more about augmentation as the article mentions and I agree, those items will be easier to maintain.
I understand that argument, but Lit isn't a web standard, and it's an esoteric choice compared to Vue, which works great with custom elements.
Lit is just a lighter weight version of that and closer to web standards without having it bolted on to a larger, almost monolithic framework now.
I still prefer direct and custom with less dependencies but Lit is somewhat trying to communicate web standards while other current frameworks really want lock-in to the platform rather than caring about making sure devs understand the standards.
That's what you get if you chose literally anything but web components. Because web components are really bad at using and playing nice with web standards: https://threadreaderapp.com/thread/1717580502280867847
They need dozens of new web standards to fix their self-inflicted wounds and to work with the browser in a way that everyone else is already working
> Additionally, web standards like Web Components/templates/custom elements will always be faster at browser level.
[citation needed]
The 2010-era design choices that web components enshrined hinder a lot of optimizations that modern frameworks are doing.
There are reasons why almost none of the modern frameworks use web components as the foundation. Including those who originally used their design or whose authors were bullish on them (Vue, Svelte, Solid).
IIRC even Angular beats Lit in benchmarks now.
The others like React/Vue/Svelte etc are all going more for platform/framework lock-in over making sure people are doing augmentation of standards.
Those frameworks have incentive to lock you in while standards are lock-in at a lower level.
Other standards I like playing with direct like html/css/canvas/WebGL/storage/svg/video/audio/geo/etc and ones that are newer are WebRTC/WebGL/WebGPU/WebAssembly etc. All of these are and will be abstracted by some frameworks and people will know less about them and more about the platforms on top if they aren't regularly going direct. I think people that know about the standards more low level make for better framework developers an developers that use frameworks even.
I like platforms that make web standards the core aim not the platform lock in.
Lit is just a lighter weight version of that and closer to web standards without having it bolted on to a larger, almost monolithic framework now.
Lit is somewhat Angular like since Google make both.
People keep repeating this mantra as if this alone makes web components good
> Those frameworks have incentive to lock you in while standards are lock-in at a lower level.
Or: these frameworks have the incentive to solve problems that web standards have been unwilling to solve for decades, and won't solve for another few decades.
> I like platforms that make web standards the core aim not the platform lock in.
Then you should use literally anything else but web components. Because web components don't make standards their core, are broken on multiple levels, and will require 20 more new standards to fix things that are not broken in literally anything else: https://threadreaderapp.com/thread/1717580502280867847
> Lit is just a lighter weight version of that and closer to web standards
The only thing that is standard in Lit is that it compiles to web components by default.
You did ask. heh.
As I mentioned, I prefer direct standards or at least frameworks that make standards a main part of the design, even if only on output.
Standards are slower to finalize, frameworks front ran them via abstractions that may have been needed for a while --like Flash with interactivity before HTML5/canvas/svg/WebGL/etc and I was huge into Flash and plugins, those days are over though. Standards will be around longer and more maintainable on standard schedules not just feature/dependency pump frameworks of today that have verbloat.
Plugins and now frameworks innovate and front run, and influence standards, then standards win the long game every single time. Like why use virtual DOM when shadowdom is now available, unnecessary abstraction now that will always lose to native dom abstractions like shadowdom.
Right now with web standards where they are at, Javascript how far it has come, and the coming WebAssembly + WebGPU platforms now being ready or close to ready, the current frameworks are about to be lapped. It is just the way things go and the typical waves in innovation to standards and repeat.
About Lit, I mentioned it as I said in another comment "if you like the component style of other frameworks but want to use Web Components, Google Lit is quite nice"
We can agree to disagree on the rest.
Unless you... server-side render them. Then your definition of "render" needs to change
1. You convert the JavaScript/JSX into HTML on the server and send it down (along with multiple blobs of JSON/code to re-hydrate).
2. The browser parses all the HTML and added JSON/code.
3. The browser then re-hydrates the page via JavaScript loading all of the JSON/code and computing everything (rendering it again).
isn't this exactly what's going on under the hood with web components? if you send an html page including <user-avatar><img></user-avatar>, the browser is going to draw the <img> tag and treat the <user-avatar> tag as a no-op because it doesn't know what to do with that. then your javascript kicks in and transforms the <user-avatar> tag into whatever the javascript defines it as, at which point it will get re-rendered.
Reddit's new redesign downloads over 100 js files: https://x.com/dmitriid/status/1708772121260732494 to render a menu.
I don't think the core idea was to ever use "hundreds" of components. HTML should be able to do a majority of the work, and you sprinkle a component here or there as needed.
Umm, that's why SSR was created?
While I write react daily and love it, I think it’s important to realize no methodology today will have any real importance or meaning 100 years from now. It’s all a means to an end and frameworks and web components are just different means.
In 2123, people will glance at a paragraph about react and move on to the next topic in programming history.
Additionally, SSR doesn't replace web components, it's a different technology with an intersecting feature. There is no problem to use them together.