Skip to content

Commit 0113b88

Browse files
Fix canonicalization of arbitrary variants with attribute selectors (#19176)
Fixes tailwindlabs/tailwindcss-intellisense#1481 We were detecting when we needed to apply the `*` and `**` variants and even detecting attribute selectors. However we only cleaned up the attribute selectors when they were `data-*` or `aria-*` attributes. This resulted in a "loop" of sorts because we'd: - See something like `[&_>_[foo]]:flex` - Notice that it needs a `*` variant - Add the `*` variant, giving `*:[&_>[foo]]:flex` - But fail to cleanup the remainder of the variant This then meant that we'd see the `*:[&_>[foo]]:flex` the next time we checked, notice that it still needed a `*` variant, and repeat… This PR fixes this case to clean up the selector.
1 parent 29687e0 commit 0113b88

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

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

1616
- Discard candidates with an empty data type ([#19172](https://github.com/tailwindlabs/tailwindcss/pull/19172))
17+
- Fix canonicalization of arbitrary variants with attribute selectors ([#19176](https://github.com/tailwindlabs/tailwindcss/pull/19176))
1718

1819
## [4.1.15] - 2025-10-20
1920

packages/tailwindcss/src/canonicalize-candidates.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,10 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
846846
['[&_>_[data-visible]]:flex', '*:data-visible:flex'],
847847
['[&>*]:flex', '*:flex'],
848848
['[&_>_*]:flex', '*:flex'],
849+
['[&_>_[foo]]:flex', '*:[[foo]]:flex'],
850+
['[&_[foo]]:flex', '**:[[foo]]:flex'],
851+
['[&_>_[foo=bar]]:flex', '*:[[foo=bar]]:flex'],
852+
['[&_[foo=bar]]:flex', '**:[[foo=bar]]:flex'],
849853

850854
['[&_[data-visible]]:flex', '**:data-visible:flex'],
851855
['[&_*]:flex', '**:flex'],

packages/tailwindcss/src/canonicalize-candidates.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,9 @@ function modernizeArbitraryValuesVariant(
16491649
!isSingleSelector(target.nodes) ||
16501650
// [foo][bar] is considered a single selector but has multiple nodes
16511651
target.nodes.length !== 1
1652-
)
1652+
) {
16531653
continue
1654+
}
16541655

16551656
// Expecting a single attribute selector
16561657
if (!isAttributeSelector(target.nodes[0])) continue
@@ -1796,6 +1797,15 @@ function modernizeArbitraryValuesVariant(
17961797
}, // aria-[foo~="true"], aria-[foo|="true"], …
17971798
} satisfies Variant)
17981799
}
1800+
1801+
// Arbitrary attributes
1802+
else {
1803+
replaceObject(variant, {
1804+
kind: 'arbitrary',
1805+
selector: target.value,
1806+
relative: false,
1807+
} satisfies Variant)
1808+
}
17991809
}
18001810

18011811
if (prefixedVariant) {

0 commit comments

Comments
 (0)