Skip to content

Commit

Permalink
Reintroduce universal selector optimization behind experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Sep 6, 2021
1 parent 2dac5bb commit a9e160c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/featureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import log from './util/log'

const featureFlags = {
future: [],
experimental: [],
experimental: ['optimizeUniversalDefaults'],
}

export function flagEnabled(config, flag) {
Expand Down
11 changes: 7 additions & 4 deletions src/lib/resolveDefaultsAtRules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import postcss from 'postcss'
import selectorParser from 'postcss-selector-parser'
import { flagEnabled } from '../featureFlags'

function minimumImpactSelector(nodes) {
let pseudos = nodes.filter((n) => n.type === 'pseudo')
Expand Down Expand Up @@ -51,7 +52,7 @@ function extractElementSelector(selector) {
return cache.get(selector)
}

export default function resolveDefaultsAtRules() {
export default function resolveDefaultsAtRules({ tailwindConfig }) {
return (root) => {
let variableNodeMap = new Map()
let universals = new Set()
Expand Down Expand Up @@ -90,9 +91,11 @@ export default function resolveDefaultsAtRules() {

let universalRule = postcss.rule()

// TODO: Fix this, this is a hotfix
// universalRule.selectors = [...selectors]
universalRule.selectors = ['*', '::before', '::after']
if (flagEnabled(tailwindConfig, 'optimizeUniversalDefaults')) {
universalRule.selectors = [...selectors]
} else {
universalRule.selectors = ['*', '::before', '::after']
}

universalRule.append(universal.nodes)
universal.before(universalRule)
Expand Down

0 comments on commit a9e160c

Please sign in to comment.