Skip to content

Commit 2242941

Browse files
authored
Refactor gradient implementation to work around prettier/prettier#17058 (#16072)
This PR fixes an issue where tools like Prettier remove important trailing commas in CSS variables, making gradients invalid. We encoded the `,` in the `--tw-gradient-position` to ensure that _if_ the `var(--tw-gradient-position)` is used, that the `,` was there. And if the variable was _not_ used that we didn't end up with a double `,,` rendering the gradient invalid. However, when running Prettier (there might be other tools that do this as well), the trailing comma in the `--tw-gradient-position` was removed which made the entire gradient invalid. E.g.: ```diff .bg-gradient-to-r { - --tw-gradient-position: to right in oklab,; + --tw-gradient-position: to right in oklab; background-image: linear-gradient(var(--tw-gradient-stops)); } ``` Notice how the `,` is removed. This PR fixes that, by moving the `,` to where the variable is being used. The only side effect is that we have to guarantee that the `--tw-gradient-position` is always present. In our testing (and using UI tests) this should be the case. Related Prettier issue: prettier/prettier#17058 Fixes: #16037
1 parent 0d5e2be commit 2242941

File tree

6 files changed

+112
-107
lines changed

6 files changed

+112
-107
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Only generate positive `grid-cols-*` and `grid-rows-*` utilities ([#16020](https://github.com/tailwindlabs/tailwindcss/pull/16020))
1313
- Ensure we process Tailwind CSS features when only using `@reference` or `@variant` ([#16057](https://github.com/tailwindlabs/tailwindcss/pull/16057))
14+
- Refactor gradient implementation to work around [prettier/prettier#17058](https://github.com/prettier/prettier/issues/17058) ([#16072](https://github.com/tailwindlabs/tailwindcss/pull/16072))
1415

1516
## [4.0.1] - 2025-01-29
1617

packages/tailwindcss/src/compat/legacy-utilities.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,42 @@ test('bg-gradient-*', async () => {
2222
),
2323
).toMatchInlineSnapshot(`
2424
".bg-gradient-to-b {
25-
--tw-gradient-position: to bottom in oklab, ;
25+
--tw-gradient-position: to bottom in oklab;
2626
background-image: linear-gradient(var(--tw-gradient-stops));
2727
}
2828
2929
.bg-gradient-to-bl {
30-
--tw-gradient-position: to bottom left in oklab, ;
30+
--tw-gradient-position: to bottom left in oklab;
3131
background-image: linear-gradient(var(--tw-gradient-stops));
3232
}
3333
3434
.bg-gradient-to-br {
35-
--tw-gradient-position: to bottom right in oklab, ;
35+
--tw-gradient-position: to bottom right in oklab;
3636
background-image: linear-gradient(var(--tw-gradient-stops));
3737
}
3838
3939
.bg-gradient-to-l {
40-
--tw-gradient-position: to left in oklab, ;
40+
--tw-gradient-position: to left in oklab;
4141
background-image: linear-gradient(var(--tw-gradient-stops));
4242
}
4343
4444
.bg-gradient-to-r {
45-
--tw-gradient-position: to right in oklab, ;
45+
--tw-gradient-position: to right in oklab;
4646
background-image: linear-gradient(var(--tw-gradient-stops));
4747
}
4848
4949
.bg-gradient-to-t {
50-
--tw-gradient-position: to top in oklab, ;
50+
--tw-gradient-position: to top in oklab;
5151
background-image: linear-gradient(var(--tw-gradient-stops));
5252
}
5353
5454
.bg-gradient-to-tl {
55-
--tw-gradient-position: to top left in oklab, ;
55+
--tw-gradient-position: to top left in oklab;
5656
background-image: linear-gradient(var(--tw-gradient-stops));
5757
}
5858
5959
.bg-gradient-to-tr {
60-
--tw-gradient-position: to top right in oklab, ;
60+
--tw-gradient-position: to top right in oklab;
6161
background-image: linear-gradient(var(--tw-gradient-stops));
6262
}"
6363
`)

packages/tailwindcss/src/compat/legacy-utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function registerLegacyUtilities(designSystem: DesignSystem) {
1414
['tl', 'top left'],
1515
]) {
1616
designSystem.utilities.static(`bg-gradient-to-${value}`, () => [
17-
decl('--tw-gradient-position', `to ${direction} in oklab,`),
17+
decl('--tw-gradient-position', `to ${direction} in oklab`),
1818
decl('background-image', `linear-gradient(var(--tw-gradient-stops))`),
1919
])
2020
}

0 commit comments

Comments
 (0)