Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve values in functional utilities based on @theme options #15623

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jan 14, 2025

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 inline was used.

We used to compile the following code:

@theme {
  --tab-size-github: 8;
}

@utility tab-* {
  tab-size: --value(--tab-size);
}

Into:

:root {
  --tab-size-github: 8;
}

.tab-github {
  tab-size: 8;
}

But it should be referencing the variable instead:

:root {
  --tab-size-github: 8;
}

.tab-github {
  tab-size: var(--tab-size-github);
}

However, if you used @theme inline reference, it should inline the value:

@theme inline reference {
  --tab-size-github: 8;
}

@utility tab-* {
  tab-size: --value(--tab-size);
}

This will now correctly compile to:

.tab-github {
  tab-size: 8;
}

@RobinMalfait RobinMalfait requested a review from a team as a code owner January 14, 2025 11:16
Comment on lines +18133 to 18134
line-height: var(--text-xs--line-height);
line-height: 6;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.:

@@ -4854,8 +4854,35 @@ function resolveValueFunction(
arg.value[0] === '-' &&
arg.value[1] === '-'
) {
let resolved = designSystem.resolveThemeValue(arg.value.replace('*', value.value))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RobinMalfait RobinMalfait changed the title Resolve values in functional utilities based on theme Resolve values in functional utilities based on @theme options Jan 14, 2025
@RobinMalfait RobinMalfait merged commit da2da51 into next Jan 14, 2025
5 checks passed
@RobinMalfait RobinMalfait deleted the fix/sometimes-inline-functional-utility-values branch January 14, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants