-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Hi, I just bumped into an issue where having a custom CSS variable defined in @theme with the same name as a custom tw @utility causes duplicate classes to be generated, with incorrect properties. This breaks the CSS and results in styles not rendering properly on the page.
I'm using the latest version of tailwind in a sveltekit project with the default configuration. I also tested this in the official tw playground and I see the same behavior. Screenshots are attached so you can immediately see that something's wrong.
I spent more than half an hour trying to find the problem. After renaming the custom variable, everything worked fine again. I believe this should be addressed, since CSS variables --custom-name and tw utilities .custom-name are diffirent concepts and shouldn't interfere with each other.
I'm running into this because I want to define a custom utils and vars for variable font in the @theme config:
@theme {
--font-400: 'wght' 400;
--font-ss-3: 'ss03' 1;
}So I can use it later with custom util:
@utility font-400 {
font-variation-settings: var(--font-400);
}
@utility font-ss-3 {
font-feature-settings: var(--font-ss-3);
}or via custom css directly if needed:
p {
font-variation-settings: var(--font-600);
font-feature-settings: var(--font-ss-3);
}These variable names should remain isolated, custom properties under @theme shouldn’t conflict with custom @utilities.
In short: everything works as expected unless a custom @theme variable shares its name with a custom @utility, in that case, CSS breaks due to conflicting class generation.