lightningcss icon indicating copy to clipboard operation
lightningcss copied to clipboard

`:where` not being transpiled for older browsers

Open KieranP opened this issue 7 months ago • 7 comments

Using lightningcss and setting the browser targets to the last 5 years, the final CSS output contains :where selectors, which have only been supported for just over 4 years (https://caniuse.com/?search=%3Awhere). Missing feature or impossible transpilation?

KieranP avatar Apr 18 '25 23:04 KieranP

This is not possible. :where changes the specificity of the selector, which is not possible to emulate.

devongovett avatar Apr 19 '25 01:04 devongovett

@devongovett Understood. Rather than silently ignore these sorts of things, would outputting warnings when syntax isn't compatible with browser targets be suitable here? e.g.

Warning: Final CSS output contains `:where` selectors, which are not compatible with browser target `last 5 years`

KieranP avatar Apr 19 '25 01:04 KieranP

That's a good idea.

devongovett avatar Apr 19 '25 01:04 devongovett

@devongovett if it's not posible to emulate :where so why then don't add some flag to remove :where from result CSS and leave it for the developer responsibility? I mean :where(.px-4) and just .pa-4 it's the same for me, I completely agree with that.

NuclleaR avatar Apr 24 '25 08:04 NuclleaR

Because then the css would be incorrect (have the wrong specificity)

devongovett avatar Apr 26 '25 17:04 devongovett

it’s true but at least it will work in old browsers

NuclleaR avatar Apr 26 '25 19:04 NuclleaR

It will appear to work in simple cases, but subtly break in the cases that rely on :where having its intended specificity.

mischnic avatar Apr 26 '25 19:04 mischnic