Closed vovsemenv closed 4 weeks ago
Hi @vovsemenv,
Thank you for reaching out about this.
Unfortunately there isn't much we can do about this. The generated CSS is correct and the smallest/simplest it can be.
We test this extremely thoroughly and pass all the same tests that browsers do.
The :root * {}
blocks are needed because of how inheritance works with light-dark()
and custom properties.
You can see this in action in this codepen: https://codepen.io/romainmenke/pen/wvLGwyb
Notice how the output for light-dark()
is computed for each child element and not only once at the root.
Maybe it is too soon to use light-dark()
with so many colors and also in a setup where everything is a custom property?
Fallbacks/polyfills can never be as performant and efficient as native implementations. Using a feature this intensive with a fallback/polyfill might not be ideal?
i end up in the selector hell
How do you mean?
These are all very low specificity selectors and shouldn't conflict with anything you wrote yourself.
Do you simply mean that there is a lot of generated CSS?
even chrome devTools stops working
That seems like an issue with dev tools, not with postcss-preset-env
?
Is there an actual problem when rendering pages? Or only a large CSS file and buggy chrome dev tools?
🤔 We can simplify one thing.
We can output a single & * {}
rule per parent rule instead one per light-dark()
.
:root {
& * {
--csstools-light-dark-toggle--1: var(--csstools-color-scheme--dark) var(--gray-neutral-900);
--constant-bg-base-primary: var(--csstools-light-dark-toggle--1, var(--constant-bg-base-primary-night));
}
}
:root {
& * {
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--system-blue-200);
--ad-other-focus: var(--csstools-light-dark-toggle--0, var(--system-blue-300));
}
}
->
:root {
& * {
--csstools-light-dark-toggle--1: var(--csstools-color-scheme--dark) var(--gray-neutral-900);
--constant-bg-base-primary: var(--csstools-light-dark-toggle--1, var(--constant-bg-base-primary-night));
--csstools-light-dark-toggle--0: var(--csstools-color-scheme--dark) var(--system-blue-200);
--ad-other-focus: var(--csstools-light-dark-toggle--0, var(--system-blue-300));
}
}
🤔 We can simplify one thing.
We can output a single
& * {}
rule per parent rule instead one perlight-dark()
.
This is actually can help a lot too!! Let me know if i can contribute that myself
You can! 😄
The contributing guides are here : https://github.com/csstools/postcss-plugins/blob/main/CONTRIBUTING.md#quick-start
The relevant code here is : https://github.com/csstools/postcss-plugins/blob/66f7becd050ab94d36594de6f0eda1b85316eaef/plugins/postcss-light-dark-function/src/index.ts#L87-L97
Keeping track of state and data can be done in the prepare
block: https://github.com/csstools/postcss-plugins/blob/66f7becd050ab94d36594de6f0eda1b85316eaef/plugins/postcss-light-dark-function/src/index.ts#L15-L18
I would likely use something like a Map()
and only create one variableInheritanceRule
for each unique decl.parent
.
Test config is here : https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-light-dark-function/test/_tape.mjs
Maybe best to create a new test CSS file : tests/common-patterns-1.css
.
A separate test file is likely more representative of your use case.
And add an entry for it in _tape.mjs
:
'common-patterns-1': {
message: 'support common patterns',
},
@romainmenke thank you very much for amazing work!!!
Thank you again for reporting this!
What would you want to propose?
I try to use do this
but since i have 150+ colors every light-dark produce new selector like this i end up in the selector hell. ( even chrome devTools stops working
Suggested solution
that lead to this result without additional selectors
Additional context
No response
Validations
Would you like to open a PR for this feature?