diff --git a/lib/getChildRules.js b/lib/getChildRules.js index 788978d..9667904 100644 --- a/lib/getChildRules.js +++ b/lib/getChildRules.js @@ -41,8 +41,11 @@ function getChildRules(css, parent) { name: atRule.name, params: atRule.params }); - // Should append even if parent selector - if (rule.selector === parent.selector || childRule) { + /** + * Should append even if parent selector, but make sure the two rules + * aren't identical. + */ + if ((rule.selector === parent.selector || childRule) && _postcss2.default.parse(rule).toString() !== _postcss2.default.parse(parent).toString()) { var clone = rule.clone(); criticalAtRule.append(clone); result.push(criticalAtRule); diff --git a/package.json b/package.json index 6190fbe..79466c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-critical-css", - "version": "2.1.4", + "version": "2.1.5", "description": "Generate critical CSS using PostCSS", "main": "index.js", "repository": { diff --git a/src/getChildRules.js b/src/getChildRules.js index c6126f7..a5b359e 100644 --- a/src/getChildRules.js +++ b/src/getChildRules.js @@ -31,8 +31,14 @@ export function getChildRules (css: Object, parent: Object): Array { name: atRule.name, params: atRule.params }) - // Should append even if parent selector - if (rule.selector === parent.selector || childRule) { + /** + * Should append even if parent selector, but make sure the two rules + * aren't identical. + */ + if ( + (rule.selector === parent.selector || childRule) && + postcss.parse(rule).toString() !== postcss.parse(parent).toString() + ) { const clone = rule.clone() criticalAtRule.append(clone) result.push(criticalAtRule)