Two caveats with webcomponents however. The first is Safari will be the bane of your existence. You should dev in safari if you can. If it works there it will work in all other browsers. The second is stay away from form elements, for now. Or if you do, use an encapsulating component that inserts a slotted input into the light dom. The form registration api isn’t fully supported yet except by chrome, and even then it’s a bit rough around the edges.
How we use web components
11–20 of 84 posts
Re: How we use web components
#12How well do web components work in the context of SEO and pagespeed scores?
I’ve had mixed results. Page speed is excellent - I built out an SPA with ~60 or so components and my uncached first paint happens in about 400ms. Cached I get 250ms (this is on prod so it includes the server latency). SEO is more difficult. I’ve been using the npm package prerender to serve up the page properly for Google/Facebook/Discord bots and for crawlers, and since using that I’ve had successful parsing, but a…
However, one of the more exciting projects in the web components space (lit.dev) now also supports proper SSR as well which is a very new thing in the world of web components. They are trying to build it in such a way that any other library can take advantage of through a common interface.
In fact there are some kind of early stage talks happening over here https://github.com/webcomponents/community-protocols where a bunch of companies like Google, Adobe, ING and others are trying to develop some open protocols on a whole bunch of topics to improve interoperability between various libraries so that no one has to buy in 100% to any one setup.
Re: How we use web components
#13For those who have used tools like Hotwire, what has your experience been like? How does it compare to something like Vue or React?
I've just started using it on a fairly simple project so I only have first impressions. But it seems like for a UI that's not too complex it could be a big timesaver. I need to spend more time with it before I can decide where I'd draw the line and switch to a full blown SPA but it definitely expands the class of apps you can build without much JS.
Re: How we use web components
#14The other thing I was worried about was that it was planned to after writing this web component lib, to wrap these components in React. Does anyone have any experience or insights into a React wrapped web component lib?
Re: How we use web components
#15Earlier quoted context omitted.
I've just started using it on a fairly simple project so I only have first impressions. But it seems like for a UI that's not too complex it could be a big timesaver. I need to spend more time with it before I can decide where I'd draw the line and switch to a full blown SPA but it definitely expands the class of apps you can build without much JS.
State management on the front end? Is that the differentiator that forces the need for a full SPA framework? Anything else that can't be done purely with web components?
You can do some client-side state management with Stimulus though.
Re: How we use web components
#16edit: Fixed a link and grammar.
Re: How we use web components
#17On the topic of web components, does anyone know if AMP is still using them? I heard they switched over to Preact but I couldn't find an official announcement.
You can totally write web components with Preact: https://preactjs.com/guide/v10/web-components/ From a quick skim of their docs, it looks like AMP still uses web components. The nice part about web components is that the users of a library don't have to care about how it's implemented, so switching to preact is a transparent change.
Re: How we use web components
#18(For comparison, in React you can pass the state down as props from a common ancestor, and in Clojure frameworks all app state is in a giant object referenced by components as needed.)
Re: How we use web components
#19Something I've never understood how to handle with vanilla web components: if there's some state that needs to be shared and kept in sync between multiple components, how do you do it? (For comparison, in React you can pass the state down as props from a common ancestor, and in Clojure frameworks all app state is in a giant object referenced by components as needed.)
How do you pass the state between an input button and a label?
Whatever technique you choose to do that (including react!) you can use it with web components.
Some frameworks like react though also solve the componentization problem, so since web components are not necessary there (and weren't ready yet when react first came out), they tend to not get used to react and friends, even if they would technically work.
Re: How we use web components
#20Earlier quoted context omitted.
You can totally write web components with Preact: https://preactjs.com/guide/v10/web-components/ From a quick skim of their docs, it looks like AMP still uses web components. The nice part about web components is that the users of a library don't have to care about how it's implemented, so switching to preact is a transparent change.
React still doesn't play seamlessly with WC right?
But it is not fully integrated with react, you have to do some work for interaction: https://www.sitepen.com/blog/wrapping-web-components-with-re...
That link is a few years old though I think the principle is the same.