In favor of Custom Elements built-ins

Photo by Franco Antonio Giovanella on Unsplash

It should surprises nobody that knows me what I think about CEs builtin extends: these are the best primitive ever as well as, imho, the most underrated one out there!

People complaining about Custom Elements builtin extends usually have these arguments:

At the very same time, the people convinced these are good arguments, do the following:

’cause if we can agree on these points, we should wonder how comes everyone is trying to solve what Custom Elements builtin extends already solved, cursing instead this part of the living DOM standard that has been working in my case since at least 2014, when I’ve written the first v0 polyfill, which also worked great for ~10 years and behind huge projects too!

This madness … but why?

And that’s all folks!

I honestly can’t read certain comments anymore … like: “don’t use builtin extends, use React” (this is not a post against React, it’s rather a post about why on earth React, among other libraries, is not using CEs builtins to solve hydration) …

I mean, is anyone actually understanding the difference between solving a problem for 80% of the Web natively and polyfill via ~1 extra K only Safari, compared to the size of any library or framework they’re using daily, plus the code needed to provide meaningful hydration there?

The polyfill, for what is worth it, could even be inlined as script, and lighthouse wouldn’t notice the difference … so why is not everyone using it already? 🤔

This is the thing I don’t really understand, and to me it feels so illogical, yet people convinced builtin extends should be avoided like hell don’t apparently get it: they’re using an indirection backed in the DOM that requires a ridiculously small amount of code to be fixed, either via an unobtrusive polyfill, or a basic library, where both via dynamic import maps would result into real zero JS overhead to serve, and all of this through 100% SSR capabilities and compatibility … so why aren’t we combining our solutions with custom elements builtin extends?

As summary

I wonder if we could try to do a step backward, so that we can jump 5 steps forward later on, through integration, as opposite of spamming avoidance, of Custom Elements builtin extends: so much potential nobody is daring to explore, apparently, beside me and very few others, but I wish that wasn’t the case.

Thanks for reading this far! ❤ Happy to hear your thoughts too 👍

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrea Giammarchi

Web, Mobile, IoT, and all JS things since 00's. Formerly JS engineer at @nokia, @facebook, @twitter.