Skip to content

Specificity issue #28

@whatisaphone

Description

@whatisaphone

I found some behavior that I think is incorrect.

Example HTML:

<div class="a">
  <div class="b">hello</div>
</div>

Example input CSS:

.b { background: red }
.a .b { color: blue }

Example output CSS:

.b, .a .b { background: initial; color: initial }
.b { background: red }
.a .b { color: blue }

Before being run through postcss-autoreset, div.b is background: red. But afterwards, it becomes background: initial because the reset rule for .a .b has higher specificity. That smells like a bug to me.

I think this plugin should only reset selectors that have a single component. There's no reason to reset .b and then also reset .a .b – it's just a waste of bytes.

In the meantime, I was able to work around the issue with this config:

    require('postcss-autoreset')({
      rulesMatcher: (rule) => rule.selector.match(/^[.][\w-]+$/),
    }),

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions