web components are good
Zach Leatherman 8585 replies 236236 likes2020 reposts66 quotes Original on BlueskyOriginal on MastodonAlso posted to Mastodon.
85 replies
the future!
HTML to build websites? 🌶️🌶️🌶️
we are so brave 🏅
just lazy mostly 💤
shhh keep that quiet (though true)
Oh right!
gives me more space to deliver more value instead of spinning my tires chasing upgrades 🚀📈💰
Can we have web components with a functional writing style. My brain can’t go back to classes
sugar it however you want
But also... classes are good.
They declaratively combine state and behavior, which is exactly what you need for UI components.
You know I love you Justin but we may never see eye-to-eye on this one. :)
I tried making the class small and used the same helpers but I still can't find any advantage the class might have over a good ol function
Now define public properties and methods. You end up having to re-invent some very class-like syntax.
I also personally much prefer class fields to hold instance state. Much easier to scan than imperative hooks. Also much easier to inspect in the debugger.
Here's the props! I'll be honest, I hadn't really considered public methods until just now. I wonder if that's a common enough use case...
To be sure, it's not perfect just yet, but it's still early, version 0. The goal is to make this better for typescript...
I guess the idea behind it is the important part.
That's an odd comparison
In your function component, you use helpers to define the element and the template (`customElement` and `html`). But you don't in the class, so it misleadingly looks more complex.
If you did the same with the class, you'd greatly simplify the codeI do use helpers in the class actually?
Sorry I missed the `html` usage. You generally wouldn't be creating the shadow root yourself, or appending dom directly. Similar, the whole getRootNode expression wouldn't be a thing. Presumably your `customElement` helper does the first two in the function component
re: shadowRoot - That depends how conscientious you are. If you don't define it yourself, it will either be inaccessible or public.
on getRootNode - I could recreate a similar customCallback helper, but that makes very little difference. That's what it sugars down to either way.
But the comparison isn't just verbosity (although even with helpers a class is still more verbose.)
It's having everything available in the same procedural scope. No reliance on the `this` binding or implicit typing. Etc...
private props = closure variables
FP is turing-complete. That kinda thing
anything classes can achieve, functions can too, but differently. And the comparison is intended to highlight that. What advantage does the class have here?
I more meant that your helper is creating the root for you. Whereas in the class component, you do it yourself (which isn't what's common in the real world - usually a library or helper is used)
You're not wrong, though I didn't want to build a framework just for the demonstration, lol. I didn't want to use Lit either or it would feel too much like I was dissing it in comparison to my own, and I don't wanna do that either, I respect Justin a lot
Give Haunted (by @xn--6j8haa.ws) a peek
Hey yes we can
they're really quite something aren't they
Using wc to create a mount point/island for preact to write preact to create isolated and reactive islands was a good idea.
I just like complicating things 😬
I’ve done something similar with Vue before! (and github.com/11ty/is-land of course)
it’s a good idea
Oh I know about 11ty and it’s island implementation, that was the inspiration 😂 (Thanks for making it)
Also worth mentioning is @astro.build’s support for rendering other web frameworks is implemented as an islands-architecture-based web component
@zachleat that was a good post
@matuzo a complex and nuanced topic
Why is WebC/Enhance possible when other fw authors seem so adverse to web components?
I just re-read your post www.zachleat.com/web/good-bad..., and would need to re-read Rich Harris’s and Ryan Carniato’s.
I find this debate confusing. Is it just that the platform is catching up for better DX?
I don’t think that question is quite the framing I’ve seen. The complaints I’ve seen is that framework folks want web components to either do more or go away altogether. My experience is that web components do quite a bit and don’t get in my way 🤷
*are
(ugh)
And being a web standard, there's a guarantee they'll be supported for a very long time, right?
Definitely need to study and play with them more.
WebC rekindled my interest in them, so did Chris Ferdinandi's videos on his channel.
Thank you Zach!
absolutely 🙌
@JesseSkinner <poop-on> would be a good web component
@zachleat @JesseSkinner also <grey-poupon>
@jaredwhite @JesseSkinner we think alike (complimentary)
@jaredwhite @zachleat @JesseSkinner
and the obligatory <gray-poupon>
Ketzer.
do you have a moment to talk about our lord and savior web components
-
@westbrook keep that chin up 🏅
They seem to fulfill my styling scoping and isolation needs so far. But I only scratched the surface.
I built a whole ui library 6 years ago using Stencil JS and it was great.
At that time I thought web components would take off really quickly…. But the reality is very different.
Really sad GitHub's catalyst.rocks is defunct. Really liked the target/action declarativeness right in the HTML.
Really want to envision a future where the page bindings (& ideally data) are all visible on the page. Catalyst for very close.
Oh sorry, catalyst was highly inspired by Stencil, that's why I mention it here.
I toy with trying to fork & update, maintain, but I feel like not-the-dude what feels like very deliberate carefully planned librarying.
are you testing the vibes, or what?
I’m just out here, living my life, man… 😅
so mystified tho
have I got a course for you scottjehl.com/learn/webcom...
heard otherwise
time for an ol’ fashioned twitter pile-on
I'm taking your course on them now!
@zachleat I think they're pretty neat
@stuffbreaker who can argue with an endorsement like this
I use them for wrappers, but accessibility wise do you add roles and other accessibility tags, say it was a button that did a API request.
this is what founders do when they’re in founder mode
🫡
Great for some usecases. Horrible for others. IMHO.
any good web components starter packs yet?
well, I know of at least one, now: go.bsky.app/KvgKwov
(recommendations welcome)
I got into heated fights defending them that got Vercel employees cussing me out and built a web version of Mac OS 9 using them does that count? 🤷
Just what I've been looking for! Good list so far 🙏
Had to double check I added you zach 😂
an eventual consistency bug I’m sure 😅
I want to be here so bad. Someday I will have a real claim. But hopefully the list is full, teaming with brilliance, before my slow ass has any claim.
I have like ~ 15 components I've made! That are probably a decade old now. Lol,
github.com/x-tag/x-tag
I would *love* to believe that
crawl into my brain
Although I, as a backend dev, disagree, I have to admit that this is a based take
They are great for somethings and WAY underused.
Every company that offer us components as part of their offering should almost certainly be using web-components
And you the only person I know who writes vanilla web components like a boss! 🔥
haha, thank you 🙌
a few more folks here: bsky.app/starter-pack...
You write vanilla web components... like some kind of psychopath???
He didn't have to upgrade lit from v1 to v2 to v3 because he kept it vanilla ... big brain move!
*But*, he doesn't have software upgrade stories to tell his grandkids about. Sad, eh?