CSS.registerProperty and @property considered harmful

css clusterfuck by committee

I recently discovered what looked like a cool new feature in CSS. After working on leveraging it to make CSS variables work even better with xinjs's css library I realized it's actually a complete disaster and must be avoided at all costs.

Oops.

Here's what I've written covering this matter in the xins documentation:

@property and CSS.registerProperty() considered harmful

This new CSS feature is well-intentioned but ill-considered. I advise against using it yourself until its serious flaws are addressed. The problem is that if someone registers a variable you're using or you register a variable someone else is using then your CSS may be broken. And you can't re-register a variable either.

This is a bit like the problem that xinjs Component works around with tagNames, but in practice far more difficult to solve. It is impossible to tell if a given instance of a given variable name is an intentional reuse (probably) or a new separate variable. No-one intentionally defines two different components with the same tag.

In a nutshell, instead of making CSS variables more dependable, it makes them inherently fragile and there's no real workaround except for generating all properties via a single javascript library that throws fits if anyone does the wrong thing. You can't know if a third party library will break your code or you will break its. It's horrible.

— Tonio Loewald,