From b8ed4811ca4e5f8ae90d9e5a4cf7a3b3ab7a40a3 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 27 Jan 2022 13:05:09 +0100 Subject: [PATCH 1/2] ensure to partition `@apply` rules generated by addComponents, addUtilities, ... --- src/processTailwindFeatures.js | 6 ++++++ tests/apply.test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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; + } + `) + }) +}) From 25f7b0a615cf5bbab06efcf7314b1c777763108f Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 27 Jan 2022 13:10:37 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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