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

Fails to merge properties for a selector with other styles present #52

Closed
Streemo opened this issue May 22, 2018 · 5 comments
Closed

Fails to merge properties for a selector with other styles present #52

Streemo opened this issue May 22, 2018 · 5 comments

Comments

@Streemo
Copy link

Streemo commented May 22, 2018

Edit: See final update below.

a.css

#root {
  background-color: #f00;
}
body {
  text-align: center;
}

b.css

#root {
  width: 640px;
  height: 360px;
}

expected.css

#root{width:640px;height:360px;background-color:red}body{text-align:center}

actual.css

#root{background-color:red}body{text-align:center}#root{width:640px;height:360px}

If the body style is omitted, it merges the #root styles as expected.

@Streemo
Copy link
Author

Streemo commented May 22, 2018

If the body declaration is first, it works as expected:

body {
  text-align: center;
}
#root {
  background-color: #f00;
}

b.css

#root {
  width: 640px;
  height: 360px;
}

actual.css === expected.css

body{text-align:center}#root{background-color:red;width:640px;height:360px}

@Streemo
Copy link
Author

Streemo commented May 22, 2018

If each declaration is in a separate file, it works as expected, depending on the import order, see next comment:

a.css

#root {
  background-color: #f00;
}

b.css

body {
  text-align: center;
}

c.css

#root {
  width: 640px;
  height: 360px;
}

actual.css === expected.css

#root{background-color:red;width:640px;height:360px}body{text-align:center}

@Streemo
Copy link
Author

Streemo commented May 22, 2018

index.js

import "a.css"
import "b.css"
import "c.css"

will produce the offending output, whereas importing a and c consecutively (the #root declarations) produced the expected output:

import "a.css"
import "c.css"
import "b.css"

So, does order matter with these sheets, really? Shouldn't they be merged anyway? I think it would be a bit cumbersome to have to optimize the order of my imports if it can be done automatically.

@NMFR
Copy link
Owner

NMFR commented May 23, 2018

Will take a look in the weekend, but i suspect it is a cssnano issue.

@NMFR
Copy link
Owner

NMFR commented Jul 15, 2018

It seems this is the expected behavior.

cssnano will only merge adjacent rules https://cssnano.co/optimisations/mergerules/

@NMFR NMFR closed this as completed Jul 15, 2018
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