Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested style have redundant CSS #9644

Merged
merged 4 commits into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

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

## [3.2.1] - 2022-10-21

Expand Down
2 changes: 1 addition & 1 deletion src/lib/generateRules.js
Expand Up @@ -210,7 +210,7 @@ function applyVariant(variant, matches, context) {
let container = postcss.root({ nodes: [rule.clone()] })

for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples) {
let clone = containerFromArray ?? container.clone()
let clone = (containerFromArray ?? container).clone()
let collectedFormats = []

function prepareBackup() {
Expand Down
37 changes: 37 additions & 0 deletions tests/variants.test.js
Expand Up @@ -1029,3 +1029,40 @@ test('class inside pseudo-class function :has', () => {
`)
})
})

test('variant functions returning arrays should output correct results when nesting', async () => {
let config = {
content: [{ raw: html`<div class="test:foo" />` }],
corePlugins: { preflight: false },
plugins: [
function ({ addUtilities, addVariant }) {
addVariant('test', () => ['@media (test)'])
addUtilities({
'.foo': {
display: 'grid',
'> *': {
'grid-column': 'span 2',
},
},
})
},
],
}

let input = css`
@tailwind utilities;
`

let result = await run(input, config)

expect(result.css).toMatchFormattedCss(css`
@media (test) {
.test\:foo {
display: grid;
}
.test\:foo > * {
grid-column: span 2;
}
}
`)
})