Skip to content

Commit 494051c

Browse files
Consider variants starting with @- to be invalid (e.g. @-2xl:flex) (#18869)
This PR fixes a small parsing issue where variants such as `@-2xl:flex` would parse, but were handled as-if they were `@2xl:flex` instead. Noticed this while working on: #18867 This is because when we parse normal variants like `data-foo` then we want to have a `data` root and a `foo` value, not a `-foo` value. If you are now using `@-2xl:flex`, then no CSS will be generated for this anymore. If you were relying on this for some reason, you should use `@2xl:flex` instead. ## Test plan Before: <img width="862" height="586" alt="image" src="https://github.com/user-attachments/assets/b5993ca6-f907-49af-b5bd-b7206c8300e1" /> After: <img width="862" height="586" alt="image" src="https://github.com/user-attachments/assets/351f45e4-4cd3-451c-ae2a-c52c3e770629" /> --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 4637069 commit 494051c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Show suggestions for known `matchVariant` values ([#18798](https://github.com/tailwindlabs/tailwindcss/pull/18798))
2121
- Replace deprecated `clip` with `clip-path` in `sr-only` ([#18769](https://github.com/tailwindlabs/tailwindcss/pull/18769))
2222
- Hide internal fields from completions in `matchUtilities` ([#18820](https://github.com/tailwindlabs/tailwindcss/pull/18820))
23+
- Ignore `.vercel` folders by default (can be overridden by `@source …` rules) ([#18855](https://github.com/tailwindlabs/tailwindcss/pull/18855))
24+
- Consider variants starting with `@-` to be invalid (e.g. `@-2xl:flex`) ([#18869](https://github.com/tailwindlabs/tailwindcss/pull/18869))
2325
- Upgrade: Migrate `aria` theme keys to `@custom-variant` ([#18815](https://github.com/tailwindlabs/tailwindcss/pull/18815))
2426
- Upgrade: Migrate `data` theme keys to `@custom-variant` ([#18816](https://github.com/tailwindlabs/tailwindcss/pull/18816))
2527
- Upgrade: Migrate `supports` theme keys to `@custom-variant` ([#18817](https://github.com/tailwindlabs/tailwindcss/pull/18817))
26-
- Ignore `.vercel` folders by default (can be overridden by `@source …` rules) ([#18855](https://github.com/tailwindlabs/tailwindcss/pull/18855))
2728

2829
## [4.1.12] - 2025-08-13
2930

packages/tailwindcss/src/candidate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ function* findRoots(input: string, exists: (input: string) => boolean): Iterable
773773
// can skip any further parsing.
774774
if (root[1] === '') break
775775

776+
// Edge case: `@-…` is not valid as a variant or a utility so we want to
777+
// skip if an `@` is followed by a `-`. Otherwise `@-2xl:flex` and
778+
// `@-2xl:flex` would be considered the same.
779+
if (root[0] === '@' && exists('@') && input[idx] === '-') break
780+
776781
yield root
777782
}
778783

packages/tailwindcss/src/variants.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,39 @@ test('container queries', async () => {
21982198
}
21992199
}"
22002200
`)
2201+
expect(
2202+
await compileCss(
2203+
css`
2204+
@theme {
2205+
--container-lg: 1024px;
2206+
--container-foo-bar: 1440px;
2207+
}
2208+
@tailwind utilities;
2209+
`,
2210+
[
2211+
'@-lg:flex',
2212+
'@-lg/name:flex',
2213+
'@-[123px]:flex',
2214+
'@-[456px]/name:flex',
2215+
'@-foo-bar:flex',
2216+
'@-foo-bar/name:flex',
2217+
2218+
'@-min-lg:flex',
2219+
'@-min-lg/name:flex',
2220+
'@-min-[123px]:flex',
2221+
'@-min-[456px]/name:flex',
2222+
'@-min-foo-bar:flex',
2223+
'@-min-foo-bar/name:flex',
2224+
2225+
'@-max-lg:flex',
2226+
'@-max-lg/name:flex',
2227+
'@-max-[123px]:flex',
2228+
'@-max-[456px]/name:flex',
2229+
'@-max-foo-bar:flex',
2230+
'@-max-foo-bar/name:flex',
2231+
],
2232+
),
2233+
).toEqual('')
22012234
})
22022235

22032236
test('variant order', async () => {

0 commit comments

Comments
 (0)