DEV Community

Thomas Reggi
Thomas Reggi

Posted on • Updated on

Framework Interoperable Component Libraries Using Lit Web Components.

TLDR: This post is made to rave about repo I found called json-schema-form-element a lit-based component library for form generation that works with all major front-end / metaframeworks, but also to show how I'm betting on Lit for the future of the web._

Lit is having a moment, one would say it's on fire 🔥🤣. It's being used everywhere from the web version of Photoshop to Microsoft's new windows app store. I think something clicked for me recently as to why lit is the major choice when it comes to the future of the web, and web components overall.

Component libraries, love them or hate them it's how web developers quickly cobble together bits of code to form a semi-usable website. From Bootstrap to things like Material UI and more recently Radix UI and Tailwind. With the way that front-end frameworks have been proliferating there are a lot of frameworks out there React, Angular, Solid, Vue, Astro and Lit. How are we able to write framework agnostic component libraries? That way you don't need to re-learn and find alternatives to the things you love to use if you want to build an app in a different framework.

Enter Shoelace an undoubtedly witty pin on "Bootstrap", that aims at bringing back direct usable components but by offering web-components by default, but it also offers web-components wrapped in a react component as well. This is at the core of building a framework interoperable component library, 1) use web-components, 2) wrap them in that specific language's syntax.

While I haven't used Shoelace directly yet, they tout that it's possible to fully customize the components styles, unlike bootstrap which was expected to be used as is. The overuse of bootstrap ultimately led to the homogenization of web-design, making websites feel "bootstrap". With things like CSS Variables and custom styles I'm hoping Shoelace doesn't fall into this trap.

I've been very passionate about a project called react-jsonschema-form (github, editor). I personally hate writing forms, and love the idea of serializable components, schema, validation all in one. I've always wanted an alternative to this project that offered an alternative to react, and possibly the ability to render a schema form to static HTML (like ssg).

I've thought about this a lot while using other frameworks like Deno Fresh which uses Preact under the hood, mainly for JSX templating, but also for islands functionality. Within that framework you can't really use React component libraries. You start to think more about generating static HTML like this example from the Deno blog [A Whole Website in a Single JavaScript File, cont'd](https://deno.com/blog/a-whole-website-in-a-single-js-file-continued, which shows building a simple webpage with routes all in one typescript file, a site that serves no Javascript to the browser.

The other day I stumbled upon my dream project the other day json-schema-form-element (github, editor) which is heavily inspired by the react counterpart. It's exactly what I wanted to make. This project, json-schema-form-element is a masterclass in how to make a modern web-component-first / "authored" library which is also interoperable with all other frameworks.

The example repo uses Astro which allows the author to demo all of the usages for the library, check it out here: index.astro. Using Astro for this is just another thing the author got right here.

I'm really excited about all this, and it makes me have some faith in the web again. I think that Lit is a step in the right direction especially the ability to do SSR / SSG and hydrate a web page. Hopefully 🤞 Shoelace can get SSR running, which is currently one hurdle, but I think it is achievable.

Anyway, what do you think of Lit? What do you think of the approach that json-schema-form-element takes at making an interoperable component library? Comment below 👇 and let me know!

Follow me on Mastodon for more thoughts on the future of web-development, web components, and typescript stuff @indieweb.social@thomasreggi.

Thomas Reggi's Mastodon Profile Image

Top comments (8)

Collapse
 
dannyengelman profile image
Danny Engelman • Edited

In 2006 I bet on jQuery to be the future of the Web

And then the browser vendors implemented things like querySelector IN the Browser...

So what happens when Apple, Mozilla and Microsoft do not implement Google Lit syntax into the Web Component standard?

Those 4 might be working together in the WHATWG; but they are still competitors. And I presume none will let Chromium grab 100% Browser market share (We would all be stuck on AMP now)

In jQuery days there were some 20 alternatives. I have worked at 2 companies where they bet on the wrong horse.. and had to ditch 1/2 million euros.

There are 60+ Alternatives to Lit; have you tried them all?

Collapse
 
0xdonut profile image
Mr F.

I picked up jQuery at the same time. Even though browsers implemented a lot of ideas and JS itself also adopted ideas, there's no doubt jQuery made it much easier to develop sites.

I think Lit is also the winner in the long term because it leverages web components, which are also being built into the browser. Over time you might not need Lit, but everything you've picked up and learnt will still be relevant.

Collapse
 
reggi profile image
Thomas Reggi

I'm observing that companies like Adobe and Microsoft are increasingly adopting Lit, which challenges React's dominance. While jQuery remains prevalent, Lit is likely to persist similarly.

According to BuiltWith's Internet technology trends, jQuery powered over 80 million websites in 2022. This is a significant lead compared to the nearly 11 million websites that used React.

The paramount concern is SSR (Server-Side Rendering). Until there's a native web component-to-string browser API that runtimes—and ideally other languages—can utilize, we're in a standstill. I doubt native browsers will prioritize server needs, particularly SSR/SSG. There might always be a need for third-party intervention to bridge this gap.

I'm receptive to any web component libraries or frameworks supporting SSR/SSG or "HTML stringification" (and ideally hydration).

Comparing jQuery to Lit isn't accurate. The web is gravitating towards servers. For evidence, consider what Next.js/Vercel has achieved with React.js. The way forward appears to hinge on a web standard, and currently, web components are our best bet and it's up to libraries like jQuery and Lit to invent what the APIs and interfaces should look like and pave the way for standardization.

Collapse
 
dannyengelman profile image
Danny Engelman • Edited

SSRG isn't something new.
The Internet is on a 15 year cycle favoring Servers versus Clients.
30 years ago I did Gopher, 15 years ago SharePoint

Thread Thread
 
reggi profile image
Thomas Reggi

I didn't say it's new I said getting browsers to care about it is.

Thread Thread
 
dannyengelman profile image
Danny Engelman

SSR is a minor issue, has been done for over 30 years, just needs to be implemented.
The WHATWG recently started discussing about Web Component persistence between browser sessions.
That is a biggie.

Collapse
 
reggi profile image
Thomas Reggi

Thoughts?

Collapse
 
fredt34 profile image
fredt34

Thanks for the link to jsfe.js.org/ - I'm going to add it on my experimental stack:

  • Bun (I never could understand node)
  • EdgeDB, because JOINs suck + it makes no sense describing your data both in your schema and your classes - EdgeDB generates all your classes
  • Elysia for route management and SSR
  • htmx because the whole C/S via json and APIs are so unnatural
  • + probably Shoelace for the Web Component UI (unless you guys can recommend other component libraries?) + some more components (probably SmartTable - it's free along a Tree component) - because InterOperability!
  • and perhaps jsfe because I'm lazy and I prefer specifying the UI (or have it generated from the DB) rather than coding it (or other solutions, but jsonforms.io/ only generates react / vue / old crazy stuff). I've been using AlpacaJS for 10+ years, but jquery is not necessary any more.

I feel Web Components and html are ways to make things lighter, not bulkier (I never wanted to dive in react / vue / angular and the like and spend months, if not years, learning them).