Skip to content

Commit 0bdd19a

Browse files
Fix nested style have redundant CSS (#9644)
* Fix nested style have redundant `CSS` * wip * Update changelog Co-authored-by: Jordan Pittman <[email protected]>
1 parent e63c111 commit 0bdd19a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Escape special characters in resolved content base paths ([#9650](https://github.com/tailwindlabs/tailwindcss/pull/9650))
13+
- Don't reuse container for array returning variant functions ([#9644](https://github.com/tailwindlabs/tailwindcss/pull/9644))
1314

1415
## [3.2.1] - 2022-10-21
1516

src/lib/generateRules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function applyVariant(variant, matches, context) {
210210
let container = postcss.root({ nodes: [rule.clone()] })
211211

212212
for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples) {
213-
let clone = containerFromArray ?? container.clone()
213+
let clone = (containerFromArray ?? container).clone()
214214
let collectedFormats = []
215215

216216
function prepareBackup() {

tests/variants.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -1029,3 +1029,40 @@ test('class inside pseudo-class function :has', () => {
10291029
`)
10301030
})
10311031
})
1032+
1033+
test('variant functions returning arrays should output correct results when nesting', async () => {
1034+
let config = {
1035+
content: [{ raw: html`<div class="test:foo" />` }],
1036+
corePlugins: { preflight: false },
1037+
plugins: [
1038+
function ({ addUtilities, addVariant }) {
1039+
addVariant('test', () => ['@media (test)'])
1040+
addUtilities({
1041+
'.foo': {
1042+
display: 'grid',
1043+
'> *': {
1044+
'grid-column': 'span 2',
1045+
},
1046+
},
1047+
})
1048+
},
1049+
],
1050+
}
1051+
1052+
let input = css`
1053+
@tailwind utilities;
1054+
`
1055+
1056+
let result = await run(input, config)
1057+
1058+
expect(result.css).toMatchFormattedCss(css`
1059+
@media (test) {
1060+
.test\:foo {
1061+
display: grid;
1062+
}
1063+
.test\:foo > * {
1064+
grid-column: span 2;
1065+
}
1066+
}
1067+
`)
1068+
})

0 commit comments

Comments
 (0)