I'm starting a new client project which more or less boils down to a typical brochure website. For the last few years however I've mostly worked on React SPAs.
During this time I've really enjoyed the React component model and certain aspects of CSS in JS which I feel I'm going to miss when working on the new project.
As a result I've been doing some cursory exploration into web components (specifically Lit) as a means of replicating some of the benefits of React that I've grown accustom to but in a more 'traditional' environment.
I'm curious to know however if anyone has experience of Web Components / Lit and if this a valid option in 2022.
KenPainter|3 years ago
But the browser native solution, "web components" proper, we have found do not have the same capabilities.
This conclusion comes from a team I lead that produces components for internal consumption by our product teams. We generate Angular and React components from our own DSL. When we considered creating web components we found they were limited in the manipulation of child content (in angular terms: projected content). There were numerous other nits that kept coming up that I don't remember.
It seems to me the web component idea itself is a zombie. This may be overstating the case because my perspective is about supporting hundreds of teams, but I sense it has no future.
postalrat|3 years ago
tompark|3 years ago
Requiring that javascript is enabled in the browser isn't a factor because my project relies on WebRTC, which requires javascript anyway. Its main value prop wouldn't exist with javascript disabled, so I'm just going to ignore that criticism.
To work across Chrome/Firefox/Safari, I avoided templates/slots by attaching the `ShadowRoot` and setting its `.innerHTML` to the result of a function that returns the html template literal string (where the function can fill variables in that string). I haven't tested this on Edge, but it works fine natively on the other browsers without any polyfills.
I love using Typescript without any client-side framework, but you might have different constraints than I do. Particularly when it comes to job search -- it seems that almost any front-end webdev position requires React/Angular/etc so you might find that it's a career-limiting move to go straight to plain Web Components as I did. I don't care because my main background is in mobile not web.
tompark|3 years ago
For example, say you use a svg button component several times on a page, and there's a filter in the SVG that you use to change the appearance of the button when it's disabled. If the filter tag doesn't have a unique ID, and one of the buttons is disabled while all the other buttons are enabled, then all the buttons will become disabled if you modify just one of them, because they're all referencing the same filter.
It's very easy to make the IDs unique by using a sequence number (as a member of the component class), incrementing the sequence number in the component constructor, and appending that sequence number to the ID every time you call the template function.
After I fixed this problem in my code, I found out that the css-tricks guy had also run into it and he did a whole write-up about it, but he was using React not Web Components: https://css-tricks.com/heres-how-i-solved-a-weird-bug-using-...
tmm84|3 years ago
thedevindevops|3 years ago
dannye|3 years ago
wizzzzzy|3 years ago