diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e6bbb5cdc1..df8a9e36e858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +### Fixed + +- Fix `@apply` order regression (in `addComponents`, `addUtilities`, ...) ([#7232](https://github.com/tailwindlabs/tailwindcss/pull/7232)) ## [3.0.17] - 2022-01-26 diff --git a/src/processTailwindFeatures.js b/src/processTailwindFeatures.js index ac535bc8d593..952e17a13762 100644 --- a/src/processTailwindFeatures.js +++ b/src/processTailwindFeatures.js @@ -16,6 +16,9 @@ export default function processTailwindFeatures(setupContext) { let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root) detectNesting()(root, result) + + // Partition apply rules that are found in the css + // itself. partitionApplyAtRules()(root, result) let context = setupContext({ @@ -42,6 +45,9 @@ export default function processTailwindFeatures(setupContext) { issueFlagNotices(context.tailwindConfig) expandTailwindAtRules(context)(root, result) + // Partition apply rules that are generated by + // addComponents, addUtilities and so on. + partitionApplyAtRules()(root, result) expandApplyAtRules(context)(root, result) evaluateTailwindFunctions(context)(root, result) substituteScreenAtRules(context)(root, result) diff --git a/tests/apply.test.js b/tests/apply.test.js index 76f35e5b8f11..ad1e906819ed 100644 --- a/tests/apply.test.js +++ b/tests/apply.test.js @@ -1253,3 +1253,36 @@ it('apply partitioning works with media queries', async () => { ${defaults} `) }) + +it('should be possible to use apply in plugins', async () => { + let config = { + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + plugins: [ + function ({ addComponents }) { + addComponents({ + '.a': { + color: 'red', + }, + '.b': { + '@apply a': {}, + color: 'blue', + }, + }) + }, + ], + } + + return run('@tailwind components', config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + .a { + color: red; + } + + .b { + color: red; + color: blue; + } + `) + }) +})