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

Ensure CSS variable shorthand uses valid CSS variables #15738

Merged
merged 5 commits into from
Jan 27, 2025

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where we didn't always correctly validated invalid CSS variables when using the CSS variable shorthand syntax.

This PR fixes that by ensuring we start with --. We can't validate that the variable exists at runtime, but we can validate if it looks like a valid CSS variable.

We can go a step further by validating if the CSS variable is valid syntax (e.g.: all characters are valid), but we can introduce this if this is causing actual issues in projects.

p-(a-b)

Used to compile to:

.p-\(a-b\) {
  padding: var(a-b);
}

But not anymore.

@RobinMalfait RobinMalfait requested a review from a team as a code owner January 23, 2025 12:22

expect(run('bg-(color:my-color)', { utilities })).toMatchInlineSnapshot(`[]`)
})

Copy link
Contributor

Choose a reason for hiding this comment

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

We should add tests for stuff like bg-foo/(bar) to make sure it's thrown out too

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good call!

@RobinMalfait RobinMalfait merged commit 193fc60 into next Jan 27, 2025
5 checks passed
@RobinMalfait RobinMalfait deleted the fix/validate-css-variable-shorthand branch January 27, 2025 11:55
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