Skip to content

Commit 3d0606b

Browse files
Fix sorting of classes that have undefined declarations (#16995)
Closes #16973 Declaration values of `undefined` are an implementation detail and skipped when printing the CSS. Thus, these should not count towards the sort order at a.. ## Test plan - See added regression test
1 parent b676da8 commit 3d0606b

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370))
1818
- _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
1919

20+
### Fixed
21+
22+
- Ensure utilities are sorted based on their actual property order ([#16995](https://github.com/tailwindlabs/tailwindcss/pull/16995))
23+
2024
## [4.0.11] - 2025-03-06
2125

2226
### Fixed

packages/tailwindcss/src/compile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ function getPropertySort(nodes: AstNode[]) {
326326
let node = q.shift()!
327327
if (node.kind === 'declaration') {
328328
// Empty strings should still be counted, e.g.: `--tw-foo:;` is valid
329-
if (node.value !== undefined) count++
329+
if (node.value === undefined) continue
330+
331+
count++
330332

331333
if (seenTwSort) continue
332334

packages/tailwindcss/src/index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,43 @@ describe('sorting', () => {
10511051
}"
10521052
`)
10531053
})
1054+
1055+
// https://github.com/tailwindlabs/tailwindcss/issues/16973
1056+
it('should not take undefined values into account when sorting', async () => {
1057+
expect(
1058+
await compileCss(
1059+
css`
1060+
@theme {
1061+
--text-sm: 0.875rem;
1062+
--text-sm--line-height: calc(1.25 / 0.875);
1063+
}
1064+
@tailwind utilities;
1065+
@utility fancy-text {
1066+
font-size: var(--text-4xl);
1067+
line-height: var(--text-4xl--line-height);
1068+
font-weight: var(--font-weight-bold);
1069+
}
1070+
`,
1071+
['fancy-text', 'text-sm'],
1072+
),
1073+
).toMatchInlineSnapshot(`
1074+
":root, :host {
1075+
--text-sm: .875rem;
1076+
--text-sm--line-height: calc(1.25 / .875);
1077+
}
1078+
1079+
.fancy-text {
1080+
font-size: var(--text-4xl);
1081+
line-height: var(--text-4xl--line-height);
1082+
font-weight: var(--font-weight-bold);
1083+
}
1084+
1085+
.text-sm {
1086+
font-size: var(--text-sm);
1087+
line-height: var(--tw-leading, var(--text-sm--line-height));
1088+
}"
1089+
`)
1090+
})
10541091
})
10551092

10561093
describe('Parsing theme values from CSS', () => {

packages/tailwindcss/src/utilities.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15036,11 +15036,6 @@ test('text', async () => {
1503615036
--leading-snug: 1.375;
1503715037
}
1503815038
15039-
.text-sm {
15040-
font-size: var(--text-sm);
15041-
line-height: var(--tw-leading, var(--text-sm--line-height));
15042-
}
15043-
1504415039
.text-\\[10px\\]\\/none {
1504515040
font-size: 10px;
1504615041
line-height: 1;
@@ -15071,6 +15066,11 @@ test('text', async () => {
1507115066
line-height: calc(var(--spacing) * 6);
1507215067
}
1507315068
15069+
.text-sm {
15070+
font-size: var(--text-sm);
15071+
line-height: var(--tw-leading, var(--text-sm--line-height));
15072+
}
15073+
1507415074
.text-sm\\/6 {
1507515075
font-size: var(--text-sm);
1507615076
line-height: calc(var(--spacing) * 6);
@@ -16748,11 +16748,11 @@ describe('custom utilities', () => {
1674816748
expect(optimizeCss(compiled).trim()).toMatchInlineSnapshot(`
1674916749
"@layer utilities {
1675016750
.text-sm {
16751-
font-size: var(--text-sm, .875rem);
16752-
line-height: var(--tw-leading, var(--text-sm--line-height, 1.25rem));
1675316751
font-size: var(--text-sm, .8755rem);
1675416752
line-height: var(--text-sm--line-height, 1.255rem);
1675516753
text-rendering: optimizeLegibility;
16754+
font-size: var(--text-sm, .875rem);
16755+
line-height: var(--tw-leading, var(--text-sm--line-height, 1.25rem));
1675616756
}
1675716757
}"
1675816758
`)

0 commit comments

Comments
 (0)