Skip to content

Commit 7b6bc50

Browse files
Split :has rules when using experimental.optimizeUniversalDefaults (#12736)
* Split `:has` rules when using optimizeUniversalDefaults * Update changelog
1 parent ce653c5 commit 7b6bc50

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
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
- Ensure max specificity of `0,0,1` for button and input Preflight rules ([#12735](https://github.com/tailwindlabs/tailwindcss/pull/12735))
1313
- Improve glob handling for folders with `(`, `)`, `[` or `]` in the file path ([#12715](https://github.com/tailwindlabs/tailwindcss/pull/12715))
14+
- Split `:has` rules when using `experimental.optimizeUniversalDefaults` ([#12736](https://github.com/tailwindlabs/tailwindcss/pull/12736))
1415

1516
### Added
1617

src/lib/resolveDefaultsAtRules.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ export default function resolveDefaultsAtRules({ tailwindConfig }) {
104104
// we consider them separately because merging the declarations into
105105
// a single rule will cause browsers that do not understand the
106106
// vendor prefix to throw out the whole rule
107+
// Additionally if a selector contains `:has` we also consider
108+
// it separately because FF only recently gained support for it
107109
let selectorGroupName =
108-
selector.includes(':-') || selector.includes('::-') ? selector : '__DEFAULT__'
110+
selector.includes(':-') || selector.includes('::-') || selector.includes(':has')
111+
? selector
112+
: '__DEFAULT__'
109113

110114
let selectors = selectorGroups.get(selectorGroupName) ?? new Set()
111115
selectorGroups.set(selectorGroupName, selectors)

tests/resolve-defaults-at-rules.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,3 +842,58 @@ test('no defaults and apply without @tailwind base', () => {
842842
`)
843843
})
844844
})
845+
846+
test('optimize universal defaults groups :has separately', () => {
847+
let config = {
848+
experimental: { optimizeUniversalDefaults: true },
849+
content: [
850+
{ raw: html`<div class="ring-1"></div>` },
851+
{ raw: html`<div class="has-[:checked]:ring-1"></div>` },
852+
],
853+
corePlugins: { preflight: false },
854+
}
855+
856+
let input = css`
857+
@tailwind base;
858+
@tailwind utilities;
859+
`
860+
861+
return run(input, config).then((result) => {
862+
return expect(result.css).toMatchFormattedCss(css`
863+
.ring-1 {
864+
--tw-ring-inset: ;
865+
--tw-ring-offset-width: 0px;
866+
--tw-ring-offset-color: #fff;
867+
--tw-ring-color: #3b82f680;
868+
--tw-ring-offset-shadow: 0 0 #0000;
869+
--tw-ring-shadow: 0 0 #0000;
870+
--tw-shadow: 0 0 #0000;
871+
--tw-shadow-colored: 0 0 #0000;
872+
}
873+
.has-\[\:checked\]\:ring-1:has(:checked) {
874+
--tw-ring-inset: ;
875+
--tw-ring-offset-width: 0px;
876+
--tw-ring-offset-color: #fff;
877+
--tw-ring-color: #3b82f680;
878+
--tw-ring-offset-shadow: 0 0 #0000;
879+
--tw-ring-shadow: 0 0 #0000;
880+
--tw-shadow: 0 0 #0000;
881+
--tw-shadow-colored: 0 0 #0000;
882+
}
883+
.ring-1 {
884+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
885+
var(--tw-ring-offset-color);
886+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width))
887+
var(--tw-ring-color);
888+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
889+
}
890+
.has-\[\:checked\]\:ring-1:has(:checked) {
891+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
892+
var(--tw-ring-offset-color);
893+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width))
894+
var(--tw-ring-color);
895+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
896+
}
897+
`)
898+
})
899+
})

0 commit comments

Comments
 (0)