by ernsheong · 8y ago · 0 comments
The picture is not so bleak for custom elements: https://caniuse.com/#feat=custom-elementsv1
Firefox also just announced that Shadow DOM arrived in a nightly:
https://bugzilla.mozilla.org/show_bug.cgi?id=1460069
https://news.ycombinator.com/item?id=17172613
Contrary to popular belief, you can start using web components WITH just custom elements and WITHOUT shadow DOM! https://twitter.com/rob_dodson/status/961780022628331520
I jumped onto this bandwagon early and struggled with Polymer 2 and HTML imports (ugh!). Now they have made the same realizations and moving forward LitElement will lead the charge toward usable and lightweight web components:
https://www.polymer-project.org/blog/2018-05-02-roadmap-upda...
https://github.com/Polymer/lit-element
Here's how you can get started: https://github.com/Polymer/pwa-starter-kit/wiki
It's not paradise, there are kinks to work out, but ultimately one can make production worthy apps with web components TODAY (polyfills available). You can sleep at night not worrying that your library will become the new jQuery someday: https://twitter.com/SaraSoueidan/status/999645120155746304
Custom elements feel like we're moving in the opposite direction from semantic markup - they just degrade into divs, so they're not particularly meaningful unless the DOM used to construct them is also descriptive and meaningful. So immediately we get Shadow DOM which hides a bunch of stuff from the end user. It's really clearly bad for accessibility and user control.
Beyond that, it's not clear to me what problem we're solving:
- Integrated templates into HTML: Okay, I get it, potentially useful. You don't need custom elements for that.
- Blocking global CSS from styling your components: Valid, but this is a really hacky way to solve that problem. What we'd prefer is CSS boundaries that don't require JS to use.
The main thing seems to be that people think the code looks cleaner than using divs and CSS classes. Which... great, I kind of agree. But why should I be so excited about what basically boils down to syntactic sugar?
The one super useful, really exciting part of web components was HTML import. HTML imports would have been amazing.
But that effort has been messed up as well - it relies on Javascript. We can already use Javascript to make AJAX requests and append content to the DOM. What we can't do is include a single header across multiple pages without building either a webapp or a preprocessor.
I think Mozilla is in the right to have dragged their feet so much on this. Beyond shadow DOM, which I'm nonplussed about, what is now possible with modern web components that wasn't already possible 3-5 years ago?
Is there a popular/well-used set of tools for the kind of web-component based projects that you're describing? Polymer is one, I recall - wasn't too keen on it last time I looked at it, would prefer more minimal/modular..
Please tell me how web components solve the issue described in the article, namely that one of UI?
I am not even going to get started on the extremely limited capabilities of these components and the need for yet another batch of dozens of frameworks to make them even remotely useful.