Skip to content

Commit a270e2c

Browse files
authored
Remove automatic var(…) injection (#13657)
This PR is a continuation of #13537. Currently we reverted the merged changes so that we can get a new alpha version out without this change. --- This PR removes automatic `var(…)` injection for arbitrary properties, values and modifiers. There are a few properties that use "dashed-ident" values, this means that you can use `--my-thing` as-is without the `var(…)` around it. E.g.: ```css .foo { /* Notice that these don't have `var(…)` */ view-timeline-name: --timeline-name; anchor-name: --sidebar; } ``` This causes issues because we are now injecting a `var(…)` where it's not needed. One potential solution is to create a list of properties where dashed idents can be used. However, they can _also_ use CSS custom properties that point to another dashed ident. E.g.: ```css .foo { --target: --sidebar; anchor-name: var(--target); } ``` A workaround that some people used is adding a `_` in front of the variable: `mt-[_--my-thing]` this way we don't automatically inject the `var(…)` around it. This is a workaround and gross. While the idea of automatic var injection is neat, this causes more trouble than it's worth. Adding `var(…)` explicitly is better. A side effect of this is that we can simplify the internals for the `candidate` data structure because we don't need to track `dashedIdent` separately anymore. <!-- 👋 Hey, thanks for your interest in contributing to Tailwind! **Please ask first before starting work on any significant new features.** It's never a fun experience to have your pull request declined after investing a lot of time and effort into a new feature. To avoid this from happening, we request that contributors create an issue to first discuss any significant new features. This includes things like adding new utilities, creating new at-rules, or adding new component examples to the documentation. https://github.com/tailwindcss/tailwindcss/blob/master/.github/CONTRIBUTING.md -->
1 parent b0b1198 commit a270e2c

File tree

6 files changed

+705
-709
lines changed

6 files changed

+705
-709
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Preserve explicit shadow color when overriding shadow size ([#14458](https://github.com/tailwindlabs/tailwindcss/pull/14458))
3636
- Preserve explicit transition duration and timing function when overriding transition property ([#14490](https://github.com/tailwindlabs/tailwindcss/pull/14490))
3737
- Change the implementation for `@import` resolution to speed up initial builds ([#14446](https://github.com/tailwindlabs/tailwindcss/pull/14446))
38+
- Remove automatic `var(…)` injection ([#13657](https://github.com/tailwindlabs/tailwindcss/pull/13657))
3839

3940
## [4.0.0-alpha.24] - 2024-09-11
4041

packages/tailwindcss/src/__snapshots__/utilities.test.ts.snap

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports[`border-* 1`] = `
3838
border-width: 12px;
3939
}
4040
41-
.border-\\[length\\:--my-width\\], .border-\\[line-width\\:--my-width\\] {
41+
.border-\\[length\\:var\\(--my-width\\)\\], .border-\\[line-width\\:var\\(--my-width\\)\\] {
4242
border-style: var(--tw-border-style);
4343
border-width: var(--my-width);
4444
}
@@ -66,19 +66,19 @@ exports[`border-* 1`] = `
6666
border-color: #0088cc80;
6767
}
6868
69-
.border-\\[--my-color\\] {
69+
.border-\\[color\\:var\\(--my-color\\)\\] {
7070
border-color: var(--my-color);
7171
}
7272
73-
.border-\\[--my-color\\]\\/50 {
73+
.border-\\[color\\:var\\(--my-color\\)\\]\\/50 {
7474
border-color: color-mix(in srgb, var(--my-color) 50%, transparent);
7575
}
7676
77-
.border-\\[color\\:--my-color\\] {
77+
.border-\\[var\\(--my-color\\)\\] {
7878
border-color: var(--my-color);
7979
}
8080
81-
.border-\\[color\\:--my-color\\]\\/50 {
81+
.border-\\[var\\(--my-color\\)\\]\\/50 {
8282
border-color: color-mix(in srgb, var(--my-color) 50%, transparent);
8383
}
8484
@@ -159,7 +159,7 @@ exports[`border-b-* 1`] = `
159159
border-bottom-width: 12px;
160160
}
161161
162-
.border-b-\\[length\\:--my-width\\], .border-b-\\[line-width\\:--my-width\\] {
162+
.border-b-\\[length\\:var\\(--my-width\\)\\], .border-b-\\[line-width\\:var\\(--my-width\\)\\] {
163163
border-bottom-style: var(--tw-border-style);
164164
border-bottom-width: var(--my-width);
165165
}
@@ -187,19 +187,19 @@ exports[`border-b-* 1`] = `
187187
border-bottom-color: #0088cc80;
188188
}
189189
190-
.border-b-\\[--my-color\\] {
190+
.border-b-\\[color\\:var\\(--my-color\\)\\] {
191191
border-bottom-color: var(--my-color);
192192
}
193193
194-
.border-b-\\[--my-color\\]\\/50 {
194+
.border-b-\\[color\\:var\\(--my-color\\)\\]\\/50 {
195195
border-bottom-color: color-mix(in srgb, var(--my-color) 50%, transparent);
196196
}
197197
198-
.border-b-\\[color\\:--my-color\\] {
198+
.border-b-\\[var\\(--my-color\\)\\] {
199199
border-bottom-color: var(--my-color);
200200
}
201201
202-
.border-b-\\[color\\:--my-color\\]\\/50 {
202+
.border-b-\\[var\\(--my-color\\)\\]\\/50 {
203203
border-bottom-color: color-mix(in srgb, var(--my-color) 50%, transparent);
204204
}
205205
@@ -280,7 +280,7 @@ exports[`border-e-* 1`] = `
280280
border-inline-end-width: 12px;
281281
}
282282
283-
.border-e-\\[length\\:--my-width\\], .border-e-\\[line-width\\:--my-width\\] {
283+
.border-e-\\[length\\:var\\(--my-width\\)\\], .border-e-\\[line-width\\:var\\(--my-width\\)\\] {
284284
border-inline-end-style: var(--tw-border-style);
285285
border-inline-end-width: var(--my-width);
286286
}
@@ -308,19 +308,19 @@ exports[`border-e-* 1`] = `
308308
border-inline-end-color: #0088cc80;
309309
}
310310
311-
.border-e-\\[--my-color\\] {
311+
.border-e-\\[color\\:var\\(--my-color\\)\\] {
312312
border-inline-end-color: var(--my-color);
313313
}
314314
315-
.border-e-\\[--my-color\\]\\/50 {
315+
.border-e-\\[color\\:var\\(--my-color\\)\\]\\/50 {
316316
border-inline-end-color: color-mix(in srgb, var(--my-color) 50%, transparent);
317317
}
318318
319-
.border-e-\\[color\\:--my-color\\] {
319+
.border-e-\\[var\\(--my-color\\)\\] {
320320
border-inline-end-color: var(--my-color);
321321
}
322322
323-
.border-e-\\[color\\:--my-color\\]\\/50 {
323+
.border-e-\\[var\\(--my-color\\)\\]\\/50 {
324324
border-inline-end-color: color-mix(in srgb, var(--my-color) 50%, transparent);
325325
}
326326
@@ -401,7 +401,7 @@ exports[`border-l-* 1`] = `
401401
border-left-width: 12px;
402402
}
403403
404-
.border-l-\\[length\\:--my-width\\], .border-l-\\[line-width\\:--my-width\\] {
404+
.border-l-\\[length\\:var\\(--my-width\\)\\], .border-l-\\[line-width\\:var\\(--my-width\\)\\] {
405405
border-left-style: var(--tw-border-style);
406406
border-left-width: var(--my-width);
407407
}
@@ -429,19 +429,19 @@ exports[`border-l-* 1`] = `
429429
border-left-color: #0088cc80;
430430
}
431431
432-
.border-l-\\[--my-color\\] {
432+
.border-l-\\[color\\:var\\(--my-color\\)\\] {
433433
border-left-color: var(--my-color);
434434
}
435435
436-
.border-l-\\[--my-color\\]\\/50 {
436+
.border-l-\\[color\\:var\\(--my-color\\)\\]\\/50 {
437437
border-left-color: color-mix(in srgb, var(--my-color) 50%, transparent);
438438
}
439439
440-
.border-l-\\[color\\:--my-color\\] {
440+
.border-l-\\[var\\(--my-color\\)\\] {
441441
border-left-color: var(--my-color);
442442
}
443443
444-
.border-l-\\[color\\:--my-color\\]\\/50 {
444+
.border-l-\\[var\\(--my-color\\)\\]\\/50 {
445445
border-left-color: color-mix(in srgb, var(--my-color) 50%, transparent);
446446
}
447447
@@ -522,7 +522,7 @@ exports[`border-r-* 1`] = `
522522
border-right-width: 12px;
523523
}
524524
525-
.border-r-\\[length\\:--my-width\\], .border-r-\\[line-width\\:--my-width\\] {
525+
.border-r-\\[length\\:var\\(--my-width\\)\\], .border-r-\\[line-width\\:var\\(--my-width\\)\\] {
526526
border-right-style: var(--tw-border-style);
527527
border-right-width: var(--my-width);
528528
}
@@ -550,19 +550,19 @@ exports[`border-r-* 1`] = `
550550
border-right-color: #0088cc80;
551551
}
552552
553-
.border-r-\\[--my-color\\] {
553+
.border-r-\\[color\\:var\\(--my-color\\)\\] {
554554
border-right-color: var(--my-color);
555555
}
556556
557-
.border-r-\\[--my-color\\]\\/50 {
557+
.border-r-\\[color\\:var\\(--my-color\\)\\]\\/50 {
558558
border-right-color: color-mix(in srgb, var(--my-color) 50%, transparent);
559559
}
560560
561-
.border-r-\\[color\\:--my-color\\] {
561+
.border-r-\\[var\\(--my-color\\)\\] {
562562
border-right-color: var(--my-color);
563563
}
564564
565-
.border-r-\\[color\\:--my-color\\]\\/50 {
565+
.border-r-\\[var\\(--my-color\\)\\]\\/50 {
566566
border-right-color: color-mix(in srgb, var(--my-color) 50%, transparent);
567567
}
568568
@@ -643,7 +643,7 @@ exports[`border-s-* 1`] = `
643643
border-inline-start-width: 12px;
644644
}
645645
646-
.border-s-\\[length\\:--my-width\\], .border-s-\\[line-width\\:--my-width\\] {
646+
.border-s-\\[length\\:var\\(--my-width\\)\\], .border-s-\\[line-width\\:var\\(--my-width\\)\\] {
647647
border-inline-start-style: var(--tw-border-style);
648648
border-inline-start-width: var(--my-width);
649649
}
@@ -671,19 +671,19 @@ exports[`border-s-* 1`] = `
671671
border-inline-start-color: #0088cc80;
672672
}
673673
674-
.border-s-\\[--my-color\\] {
674+
.border-s-\\[color\\:var\\(--my-color\\)\\] {
675675
border-inline-start-color: var(--my-color);
676676
}
677677
678-
.border-s-\\[--my-color\\]\\/50 {
678+
.border-s-\\[color\\:var\\(--my-color\\)\\]\\/50 {
679679
border-inline-start-color: color-mix(in srgb, var(--my-color) 50%, transparent);
680680
}
681681
682-
.border-s-\\[color\\:--my-color\\] {
682+
.border-s-\\[var\\(--my-color\\)\\] {
683683
border-inline-start-color: var(--my-color);
684684
}
685685
686-
.border-s-\\[color\\:--my-color\\]\\/50 {
686+
.border-s-\\[var\\(--my-color\\)\\]\\/50 {
687687
border-inline-start-color: color-mix(in srgb, var(--my-color) 50%, transparent);
688688
}
689689
@@ -764,7 +764,7 @@ exports[`border-t-* 1`] = `
764764
border-top-width: 12px;
765765
}
766766
767-
.border-t-\\[length\\:--my-width\\], .border-t-\\[line-width\\:--my-width\\] {
767+
.border-t-\\[length\\:var\\(--my-width\\)\\], .border-t-\\[line-width\\:var\\(--my-width\\)\\] {
768768
border-top-style: var(--tw-border-style);
769769
border-top-width: var(--my-width);
770770
}
@@ -792,19 +792,19 @@ exports[`border-t-* 1`] = `
792792
border-top-color: #0088cc80;
793793
}
794794
795-
.border-t-\\[--my-color\\] {
795+
.border-t-\\[color\\:var\\(--my-color\\)\\] {
796796
border-top-color: var(--my-color);
797797
}
798798
799-
.border-t-\\[--my-color\\]\\/50 {
799+
.border-t-\\[color\\:var\\(--my-color\\)\\]\\/50 {
800800
border-top-color: color-mix(in srgb, var(--my-color) 50%, transparent);
801801
}
802802
803-
.border-t-\\[color\\:--my-color\\] {
803+
.border-t-\\[var\\(--my-color\\)\\] {
804804
border-top-color: var(--my-color);
805805
}
806806
807-
.border-t-\\[color\\:--my-color\\]\\/50 {
807+
.border-t-\\[var\\(--my-color\\)\\]\\/50 {
808808
border-top-color: color-mix(in srgb, var(--my-color) 50%, transparent);
809809
}
810810
@@ -897,7 +897,7 @@ exports[`border-x-* 1`] = `
897897
border-right-width: 12px;
898898
}
899899
900-
.border-x-\\[length\\:--my-width\\], .border-x-\\[line-width\\:--my-width\\] {
900+
.border-x-\\[length\\:var\\(--my-width\\)\\], .border-x-\\[line-width\\:var\\(--my-width\\)\\] {
901901
border-left-style: var(--tw-border-style);
902902
border-right-style: var(--tw-border-style);
903903
border-left-width: var(--my-width);
@@ -935,22 +935,22 @@ exports[`border-x-* 1`] = `
935935
border-right-color: #0088cc80;
936936
}
937937
938-
.border-x-\\[--my-color\\] {
938+
.border-x-\\[color\\:var\\(--my-color\\)\\] {
939939
border-left-color: var(--my-color);
940940
border-right-color: var(--my-color);
941941
}
942942
943-
.border-x-\\[--my-color\\]\\/50 {
943+
.border-x-\\[color\\:var\\(--my-color\\)\\]\\/50 {
944944
border-left-color: color-mix(in srgb, var(--my-color) 50%, transparent);
945945
border-right-color: color-mix(in srgb, var(--my-color) 50%, transparent);
946946
}
947947
948-
.border-x-\\[color\\:--my-color\\] {
948+
.border-x-\\[var\\(--my-color\\)\\] {
949949
border-left-color: var(--my-color);
950950
border-right-color: var(--my-color);
951951
}
952952
953-
.border-x-\\[color\\:--my-color\\]\\/50 {
953+
.border-x-\\[var\\(--my-color\\)\\]\\/50 {
954954
border-left-color: color-mix(in srgb, var(--my-color) 50%, transparent);
955955
border-right-color: color-mix(in srgb, var(--my-color) 50%, transparent);
956956
}
@@ -1050,7 +1050,7 @@ exports[`border-y-* 1`] = `
10501050
border-bottom-width: 12px;
10511051
}
10521052
1053-
.border-y-\\[length\\:--my-width\\], .border-y-\\[line-width\\:--my-width\\] {
1053+
.border-y-\\[length\\:var\\(--my-width\\)\\], .border-y-\\[line-width\\:var\\(--my-width\\)\\] {
10541054
border-top-style: var(--tw-border-style);
10551055
border-bottom-style: var(--tw-border-style);
10561056
border-top-width: var(--my-width);
@@ -1088,22 +1088,22 @@ exports[`border-y-* 1`] = `
10881088
border-bottom-color: #0088cc80;
10891089
}
10901090
1091-
.border-y-\\[--my-color\\] {
1091+
.border-y-\\[color\\:var\\(--my-color\\)\\] {
10921092
border-top-color: var(--my-color);
10931093
border-bottom-color: var(--my-color);
10941094
}
10951095
1096-
.border-y-\\[--my-color\\]\\/50 {
1096+
.border-y-\\[color\\:var\\(--my-color\\)\\]\\/50 {
10971097
border-top-color: color-mix(in srgb, var(--my-color) 50%, transparent);
10981098
border-bottom-color: color-mix(in srgb, var(--my-color) 50%, transparent);
10991099
}
11001100
1101-
.border-y-\\[color\\:--my-color\\] {
1101+
.border-y-\\[var\\(--my-color\\)\\] {
11021102
border-top-color: var(--my-color);
11031103
border-bottom-color: var(--my-color);
11041104
}
11051105
1106-
.border-y-\\[color\\:--my-color\\]\\/50 {
1106+
.border-y-\\[var\\(--my-color\\)\\]\\/50 {
11071107
border-top-color: color-mix(in srgb, var(--my-color) 50%, transparent);
11081108
border-bottom-color: color-mix(in srgb, var(--my-color) 50%, transparent);
11091109
}

0 commit comments

Comments
 (0)