Resolve values in functional utilities based on @theme options#15623
Merged
RobinMalfait merged 4 commits intoJan 14, 2025
Conversation
RobinMalfait
commented
Jan 14, 2025
Comment on lines
+18133
to
18134
| line-height: var(--text-xs--line-height); | ||
| line-height: 6; |
Member
Author
There was a problem hiding this comment.
Before this change, we also generated 2 line-height declarations, but Lightning CSS collapsed it. However, now that one is generating a variable, Lightning CSS is not optimizing it.
E.g.:
- Before: https://lightningcss.dev/playground/index.html#%7B%22minify%22%3Afalse%2C%22customMedia%22%3Atrue%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22include%22%3A0%2C%22exclude%22%3A0%2C%22source%22%3A%22.foo%20%7B%5Cn%20%20font-size%3A%20.75rem%3B%5Cn%20%20line-height%3A%208%3B%5Cn%20%20line-height%3A%206%3B%5Cn%7D%22%2C%22visitorEnabled%22%3Afalse%2C%22visitor%22%3A%22%7B%5Cn%20%20Color(color)%20%7B%5Cn%20%20%20%20if%20(color.type%20%3D%3D%3D%20'rgb')%20%7B%5Cn%20%20%20%20%20%20color.g%20%3D%200%3B%5Cn%20%20%20%20%20%20return%20color%3B%5Cn%20%20%20%20%7D%5Cn%20%20%7D%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D
- After: https://lightningcss.dev/playground/index.html#%7B%22minify%22%3Afalse%2C%22customMedia%22%3Atrue%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22include%22%3A0%2C%22exclude%22%3A0%2C%22source%22%3A%22.foo%20%7B%5Cn%20%20font-size%3A%20.75rem%3B%5Cn%20%20line-height%3A%20var(--foo)%3B%5Cn%20%20line-height%3A%206%3B%5Cn%7D%22%2C%22visitorEnabled%22%3Afalse%2C%22visitor%22%3A%22%7B%5Cn%20%20Color(color)%20%7B%5Cn%20%20%20%20if%20(color.type%20%3D%3D%3D%20'rgb')%20%7B%5Cn%20%20%20%20%20%20color.g%20%3D%200%3B%5Cn%20%20%20%20%20%20return%20color%3B%5Cn%20%20%20%20%7D%5Cn%20%20%7D%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D
| arg.value[0] === '-' && | ||
| arg.value[1] === '-' | ||
| ) { | ||
| let resolved = designSystem.resolveThemeValue(arg.value.replace('*', value.value)) |
Member
Author
There was a problem hiding this comment.
resolveThemeValue is fully resolving the value because we passed it a value like --text-sm--line-height.
Instead, we should use the resolveWith in case of nested keys.
@theme options
philipp-spiess
approved these changes
Jan 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where functional utilities configured via CSS don't resolve the values correctly.
We always fully resolved the values as-if a
@theme inlinewas used.We used to compile the following code:
Into:
But it should be referencing the variable instead:
However, if you used
@theme inline reference, it should inline the value:This will now correctly compile to: