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

CSS selectors with multiple rules redeclared in media queries results in multiple blocks #109

Closed
runar opened this issue Sep 27, 2019 · 6 comments

Comments

@runar
Copy link

runar commented Sep 27, 2019

I believe this issue is related to both #64 and #67, but it’s not quite the same as no duplication is involved.

If a CSS selector has multiple rules that are redeclared by the same media query, multiple media queries will be outputted with only one rule each. Take a look at the following example from the playground:

Input:

:root {
  --background: #fff;
  --color: #000;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #000;
    --color: #fff;
  }
}

body {
  background-color: var(--background);
  color: var(--color);
}

Expected:

body {
  background-color: #fff;
  color: #000;
}

@media (prefers-color-scheme: dark) {
  body {
    background-color: #000;
    color: #fff;
  }
}

Actual output:

body {
  background-color: #fff;
  color: #000;
}

@media (prefers-color-scheme: dark) {

  body {
  color: #fff;
  }
}

@media (prefers-color-scheme: dark) {

  body {
  background-color: #000;
  }
}

(Also notice how the rule order is reversed, indention is wrong, and an empty line is added below the media queries.)

@MadLittleMods
Copy link
Owner

MadLittleMods commented Sep 27, 2019

@runar Please add the actual output and expected output to the issue description

@runar
Copy link
Author

runar commented Sep 27, 2019

@runar Please add the actual output and expected output to the issue description

I apologize, I submitted the issue a bit too early by mistake. I’ve updated the first comment now, with expected and actual output!

@MadLittleMods
Copy link
Owner

MadLittleMods commented Sep 27, 2019

@runar This looks like it stems from the same problem as #67 so I am going to close in favor of that

You can fix the rule order with options.preserveAtRulesOrder

There isn't an existing issue for indentation weirdness. Not too high priority compared to the bugs in this project

@runar
Copy link
Author

runar commented Sep 27, 2019

@MadLittleMods Would you be able to point me in the right direction to fix this? I lack the skills to debug this on my own, but I’ll give it a shot if you help me out with what files or functions might be the culprit.

For the record, this change by @codyhouse seems to fix issue #67, but not the issue reported here.

@MadLittleMods
Copy link
Owner

MadLittleMods commented Sep 27, 2019

@runar All of the logic would be in these files,

But it probably won't be very straightforward to fix

@runar
Copy link
Author

runar commented Sep 27, 2019

@MadLittleMods You’re right, so instead of spending the entire weekend on this, I’ll be happy with my own solution: Use PostCSS and cssnano (the mergeRules optimisation) to merge the media queries into one.

Thank you for responding so quickly!

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

No branches or pull requests

2 participants