Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specificity issue #28

Closed
whatisaphone opened this issue Jun 7, 2018 · 2 comments
Closed

Specificity issue #28

whatisaphone opened this issue Jun 7, 2018 · 2 comments
Labels

Comments

@whatisaphone
Copy link

whatisaphone commented Jun 7, 2018

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-]+$/),
    }),
@maximkoretskiy
Copy link
Owner

Hi, and thank You for the suggestion.
As the main idea of this plugin is the isolation of all CSS rules, we could not change its default behavior to match Your concrete case. I mean, we could have an outer rule with the same selector (i.e. .a .b), and the most expectable for plugin behavior is to add all mentioned in project rules into reset until you decide to change this behavior.
rulesMatcher is aimed to solve this case and You used it properly.

@maximkoretskiy
Copy link
Owner

Mentioned your issue in README. Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants