Skip to content

Commit b9af722

Browse files
authored
Fix remove !important on CSS variable declarations (#16668)
This PR fixes an issue where `!important` is added to declarations that define CSS variables. The `!important` should only be added to the other declarations. Before: ```css .ease-out\! { --tw-ease: var(--ease-out) !important; transition-timing-function: var(--ease-out) !important; } ``` After: ```css .ease-out\! { --tw-ease: var(--ease-out); transition-timing-function: var(--ease-out) !important; } ``` Fixes: #16664
1 parent 61af484 commit b9af722

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370))
1313

14+
### Fixed
15+
16+
- Remove invalid `!important` on CSS variable declarations ([#16668](https://github.com/tailwindlabs/tailwindcss/pull/16668))
17+
1418
## [4.0.7] - 2025-02-18
1519

1620
### Fixed

packages/tailwindcss/src/compile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function applyImportant(ast: AstNode[]): void {
300300
continue
301301
}
302302

303-
if (node.kind === 'declaration') {
303+
if (node.kind === 'declaration' && node.property[0] !== '-' && node.property[1] !== '-') {
304304
node.important = true
305305
} else if (node.kind === 'rule' || node.kind === 'at-rule') {
306306
applyImportant(node.nodes)

packages/tailwindcss/src/important.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test } from 'vitest'
22
import { compile } from '.'
3+
import { compileCss } from './test-utils/run'
34

45
const css = String.raw
56

@@ -87,3 +88,31 @@ test('Utilities can be wrapped with a selector and marked as important', async (
8788
"
8889
`)
8990
})
91+
92+
test('variables in utilities should not be marked as important', async () => {
93+
expect(
94+
await compileCss(
95+
css`
96+
@theme {
97+
--ease-out: cubic-bezier(0, 0, 0.2, 1);
98+
}
99+
@tailwind utilities;
100+
`,
101+
['ease-out!'],
102+
),
103+
).toMatchInlineSnapshot(`
104+
":root, :host {
105+
--ease-out: cubic-bezier(0, 0, .2, 1);
106+
}
107+
108+
.ease-out\\! {
109+
--tw-ease: var(--ease-out);
110+
transition-timing-function: var(--ease-out) !important;
111+
}
112+
113+
@property --tw-ease {
114+
syntax: "*";
115+
inherits: false
116+
}"
117+
`)
118+
})

0 commit comments

Comments
 (0)