Skip to content

Commit ff8b2a0

Browse files
Fix extraction of quoted arbitrary variants in v3 (#20374)
## Summary Fixes #18387. The v3 default extractor did not capture the complete candidate when a standard variant preceded an arbitrary selector containing quoted values, such as `focus-visible:[&:not([aria-selected="true"])]:bg-red-500`. The quote-aware pattern allowed quote characters in the standard-variant portion, causing extraction to begin at the surrounding `class` or `className` attribute and split the candidate. This change excludes single and double quotes from that portion of the pattern while continuing to allow quotes inside arbitrary variants. Regression tests cover both single- and double-quoted selectors with preceding `focus-visible` and `hover` variants. [ci-all] ## Test plan * `npx jest tests/default-extractor.test.js tests/arbitrary-variants.test.js --runInBand` * `npm test -- --runInBand` Results: * 86 test suites passed * 1,060 tests passed * 1 test marked todo * 4 snapshots passed --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent f38be22 commit ff8b2a0

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Ensure classes are extracted when a variant precedes an arbitrary variant containing a quoted attribute selector (e.g. `focus-visible:[&:not([aria-selected="true"])]:bg-red-500`) ([#20374](https://github.com/tailwindlabs/tailwindcss/pull/20374))
1113

1214
## [3.4.19] - 2025-12-10
1315

‎src/lib/defaultExtractor.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function* buildRegExps(context) {
133133
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]\/[\w_-]+/, separator]),
134134

135135
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]/, separator]),
136-
regex.pattern([/[^\s`\[\\]+/, separator]),
136+
regex.pattern([/[^\s"'`\[\\]+/, separator]),
137137
]),
138138
]
139139

‎tests/default-extractor.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,14 @@ it.each([
576576
expect(extractions).toContain(value)
577577
}
578578
})
579+
580+
// https://github.com/tailwindlabs/tailwindcss/issues/18387
581+
test('arbitrary not selector with preceding variants', () => {
582+
let extractions = defaultExtractor(`
583+
<div class="focus-visible:[&:not([aria-selected='true'])]:bg-red-500"></div>
584+
<div class='hover:[&:not([aria-selected="true"])]:bg-red-500'></div>
585+
`)
586+
587+
expect(extractions).toContain("focus-visible:[&:not([aria-selected='true'])]:bg-red-500")
588+
expect(extractions).toContain('hover:[&:not([aria-selected="true"])]:bg-red-500')
589+
})

0 commit comments

Comments
 (0)