stephband
3.6K posts
stephband
@stephband
Bluesky: @stephen.band Mastodon: @[email protected] https://t.co/tbD0aJhdcO co-founder. Front-end developer. Musician.
Norway, Switzerland and Iceland show us how small countries not in EU can do so much better than the EU. It is nonsense to say the EU‘s size is crucial to prosperity. The single market is an unhelpful over regulated customs union.




Not really. Firstly I reject the premise that pushing the burden onto users is desirable — if a tax has to be paid, it's better for frameworks to pay it. But beyond that, it's not just about the fact that WCs make the platform so much more complex and so much harder to learn. It directly affects users in subtle ways. For example if you want to clone some DOM to build a component you can just do `fragment.cloneNode(true)`, right? Not so fast — if the DOM contains a custom element, the clone won't be assigned the correct class until it's appended to the document, and if you set properties in the meantime it won't trigger accessors (they'll shadow the prototype instead, which is very bad news). It's a real head-scratcher of a bug. It turns out that if you use `document.importNode(fragment, true)` instead, it works correctly. Not that you'll casually learn that while reading MDN — this is the kind of knowledge that is only acquired with a side helping of battle scars. But there's a catch! importNode is roughly 30% slower than cloneNode in our testing. That's unacceptable overhead given that most people aren't using custom elements (and certainly not that often). So we opted to pay a different price — the compiler adds a flag to the generated code, and the flag tells the runtime which to use. That's extra code, and extra work (albeit a miniscule amount), that would be unnecessary if we didn't have to think about this nonsense. Having the bug? Tax. Figuring out the solution? Tax. Implementing the fix? Tax. Documenting the code for our future selves? Tax. Adding regression tests? Tax. Running those tests on every CI job? Shipping extra code? Tax. Doing more work in a hot code path? Tax. And that's just one example. There are others. The bottom line is that framework authors could ship sooner, and could ship leaner and more reliable code, were it not for this ill-designed primitive with its myriad edge cases.














