-
Notifications
You must be signed in to change notification settings - Fork 244
Description
When I process some CSS with a browser target, it doesn't reliably change around vendor prefixes for compatibility with that target. Behold some code:
use lightningcss::targets::Browsers;
use lightningcss::stylesheet::{StyleSheet, ParserOptions, MinifyOptions, PrinterOptions};
fn main() {
let test_stylesheet = r#".foo {
-webkit-transition: background 200ms;
}"#;
let target_firefox_version = 108 << 16 | 2; // 108.0.2
let mut stylesheet = StyleSheet::parse(test_stylesheet, ParserOptions::default()).unwrap();
stylesheet.minify(MinifyOptions {
targets: Some(Browsers {
firefox: Some(target_firefox_version),
..Browsers::default()
}),
..MinifyOptions::default()
}).unwrap();
let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
println!("{}", res.code);
}Naively, we would expect this code to output something like this:
.foo {
transition: background .2s;
}However, instead, it outputs this:
.foo {
-webkit-transition: background .2s;
}...in other words, despite being targeted at modern Firefox (which doesn't require the -webkit- prefix on its transition properties), the output property is still being kept as webkit-transition rather than transpiled to transition.
If I change the input CSS to this:
.foo {
-webkit-transition: background 200ms;
transition: background 200ms;
}...then the output changes, as expected, to this:
.foo {
transition: background .2s;
}...but, while this works if the unprefixed form of transition is present, it doesn't work if only a different prefixed form is present. Given this input:
.foo {
-webkit-transition: background 200ms;
-moz-transition: background 200ms;
}...we get this output:
.foo {
-webkit-transition: background .2s;
-moz-transition: background .2s;
}...rather than a proper change over to transition.
But it's not even consistently the case that the proper output is obtained given the presence of the unprefixed form! If we switch from transition over to writing-mode, we'll find that this input:
.foo {
-webkit-writing-mode: vertical-rl;
writing-mode: vertical-rl;
}...leads to this output:
.foo {
-webkit-writing-mode: vertical-rl;
writing-mode: vertical-rl;
}So I'm not sure what's going on here, but I'm pretty confident it's not intended behavior.
(Tangentially: -webkit-writing-mode, input by itself, is also not transpiled to writing-mode. Which is a problem! Because, unlike with -webkit-transform—which Firefox 108.0.2 knows to handle the same way as unprefixed transform—Firefox doesn't recognize the -webkit-writing-mode property. A paragraph with a -webkit-writing-mode of vertical-rl, displayed in Firefox, won't be displayed as if it had a writing-mode of vertical-rl, but rather as if it had no writing-mode set at all. So this issue is potentially leading to actual incompatibilities with the target browsers, not just to uglier-but-still-compatible code.)