Skip to content

Commit 1868eb6

Browse files
authored
Fix @apply order regression (in addComponents, addUtilities, ...) (#7232)
* ensure to partition `@apply` rules generated by addComponents, addUtilities, ... * update changelog
1 parent 74997f1 commit 1868eb6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

+3-1
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+
- Fix `@apply` order regression (in `addComponents`, `addUtilities`, ...) ([#7232](https://github.com/tailwindlabs/tailwindcss/pull/7232))
1113

1214
## [3.0.17] - 2022-01-26
1315

src/processTailwindFeatures.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default function processTailwindFeatures(setupContext) {
1616
let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root)
1717

1818
detectNesting()(root, result)
19+
20+
// Partition apply rules that are found in the css
21+
// itself.
1922
partitionApplyAtRules()(root, result)
2023

2124
let context = setupContext({
@@ -42,6 +45,9 @@ export default function processTailwindFeatures(setupContext) {
4245
issueFlagNotices(context.tailwindConfig)
4346

4447
expandTailwindAtRules(context)(root, result)
48+
// Partition apply rules that are generated by
49+
// addComponents, addUtilities and so on.
50+
partitionApplyAtRules()(root, result)
4551
expandApplyAtRules(context)(root, result)
4652
evaluateTailwindFunctions(context)(root, result)
4753
substituteScreenAtRules(context)(root, result)

tests/apply.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -1253,3 +1253,36 @@ it('apply partitioning works with media queries', async () => {
12531253
${defaults}
12541254
`)
12551255
})
1256+
1257+
it('should be possible to use apply in plugins', async () => {
1258+
let config = {
1259+
content: [{ raw: html`<div class="a b"></div>` }],
1260+
corePlugins: { preflight: false },
1261+
plugins: [
1262+
function ({ addComponents }) {
1263+
addComponents({
1264+
'.a': {
1265+
color: 'red',
1266+
},
1267+
'.b': {
1268+
'@apply a': {},
1269+
color: 'blue',
1270+
},
1271+
})
1272+
},
1273+
],
1274+
}
1275+
1276+
return run('@tailwind components', config).then((result) => {
1277+
expect(result.css).toMatchFormattedCss(css`
1278+
.a {
1279+
color: red;
1280+
}
1281+
1282+
.b {
1283+
color: red;
1284+
color: blue;
1285+
}
1286+
`)
1287+
})
1288+
})

0 commit comments

Comments
 (0)