Closed Jothsa closed 7 months ago
@Jothsa Thank you for the bug report.
I think this is a much smaller example of the issue :
@layer theme {
:root {
color-scheme: dark;
--bg: light-dark(white, black);
}
}
@Jothsa we've just rolled out an update for this plugin that will likely fix your issue.
We use a slightly different approach and no longer add extra styles on :root {}
.
We haven't updated postcss-preset-env
yet, so make sure to update transitive dependencies with something like npm update
if you use postcss-preset-env
.
Would be awesome if you could let us know if everything is now working as expected. Thank you again for reporting this.
It's working fine now. Thanks so much!
Yeah, tbh, I'm not sure what happened with the css I was using in the example π I was messing around with it to see different combinations of selectors could get the plugin to work. I was using this css:
@layer theme {
:root {
color-scheme: light;
--bg: white;
@media (prefers-color-scheme: dark) {
&:not[data-theme-mode='light'] {
color-scheme: dark;
--bg: black;
}
}
&[data-theme-mode='dark'] {
color-scheme: dark;
--bg: black;
}
}
}
I wanted to make sure that if the user specifically chooses a theme the color-scheme
property will be set to whatever that theme is and if the data-theme-mode
attribute is set to auto the variables will update correctly. Now that light-dark
function removes the need to redefine the variables, I will switch to one of your examples. I'll probably use the last one.
Thanks again for the quick response and the advice on my css. I really appreciate it! On my way to go redefine a bunch of variables now π
Thank you for confirming π Always happy to help!
Bug description
Postcss-light-dark-function does not work with css cascade layers. I have variables and the rules to switch the
color-scheme
based on an attribute on the:root
element defined in a css cascade layer. However, postcss-light-dark-function adds media queries to set the values of--csstools-color-scheme--light
and--csstools-color-scheme--dark
based on the value ofprefers-color-scheme
outside of any cascade layer. This causes those rules to have a higher priority than the rules which change the variables and color schemes based on an html attribute. This conflict results in the color-scheme attribute changing to reflect the attribute on the:root
element, but the values of--csstools-color-scheme--light
and--csstools-color-scheme--dark
remaining set based on the value ofprefers-color-scheme
.Source CSS
Expected CSS
Actual CSS
Playgound example
https://preset-env.cssdb.org/playground/#JTdCJTIyc291cmNlJTIyJTNBJTIyJTQwbGF5ZXIlMjB0aGVtZSUyMCU3QiU1Q24lMjAlMjAlMjAlMjAlMjAlM0Fyb290JTIwJTdCJTVDbiUyMCUyMCU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yMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyNiU1QmRhdGEtdGhlbWUtbW9kZSUzRCU1QyUyMmxpZ2h0JTVDJTIyJTVEJTIwJTdCJTVDbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbG9yLXNjaGVtZSUzQSUyMGxpZ2h0JTNCJTVDbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjYlNUJkYXRhLXRoZW1lLW1vZGUlM0QlNUMlMjJkYXJrJTVDJTIyJTVEJTIwJTdCJTVDbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbG9yLXNjaGVtZSUzQSUyMGRhcmslM0IlNUNuJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTVDbiUyMCUyMCUyMCUyMCU3RCU1Q24lN0QlMjIlMkMlMjJjb25maWclMjIlM0ElN0IlMjJicm93c2VycyUyMiUzQSU1QiUyMiUzRSUyMDElMjUlMjIlNUQlMkMlMjJtaW5pbXVtVmVuZG9ySW1wbGVtZW50YXRpb25zJTIyJTNBMCUyQyUyMnN0YWdlJTIyJTNBMiUyQyUyMmxvZ2ljYWwlMjIlM0ElN0IlMjJpbmxpbmVEaXJlY3Rpb24lMjIlM0ElMjJsZWZ0LXRvLXJpZ2h0JTIyJTJDJTIyYmxvY2tEaXJlY3Rpb24lMjIlM0ElMjJ0b3AtdG8tYm90dG9tJTIyJTdEJTJDJTIyZmVhdHVyZXMlMjIlM0ElN0IlMjJuZXN0aW5nLXJ1bGVzJTIyJTNBJTVCJTIyYXV0byUyMiUyQyU3QiUyMmVkaXRpb24lMjIlM0ElMjIyMDI0LTAyJTIyJTdEJTVEJTdEJTdEJTdE
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?Yes
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
PostCSS Light Dark Function
Plugin version
1.0.2
What OS are you experiencing this on?
macOS
Node Version
20.10.0
Validations
Would you like to open a PR for this bug?