-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Building mixins should combine duplicate nested selectors #930
Comments
+1 |
1 similar comment
+1 |
If implemented, this would need to not be automatic ( except, perhaps, in the case of the two directly following one another in the code, as the minimal example above does), and probably something that needs to be switched for each instantiation of the mixin (rather than a global setting, though a global setting might control the default, with the individual switch either turning on or off the setting--whatever is opposite the global setting). This is because of various possible html configurations and cascade concerns that are impossible to know "automatically," and thus should be individually thought through by the designer/coder. In short, this can cause issues: Assume this html:
Assume this case of mixin (also "simplified"):
If For further discussion on the issues of any automated form of this, see this Stack Overflow answer to a question about this. |
@scottgit IMO, the example you pointed to is a better example of how to write brittle code. In any case, this is easily resolved by making automatic merging an option, and make it |
@jonschlinkert Thanks for you further thoughts. It may be a bit brittle (and looks more so in the minimal test case), in that it relies on equal specificity and the cascade. But if you consider that this scenario is actually quite common in a situation where a framework library is providing the original definitions of The "rule replacement" feature you linked to would give more individual control, but it would still need to be determined if the replacement occurs in the css cascade at the point of the original or at the point of the replacement code, because with output css, the cascade can and does matter. This is why even if automatic merging is set to |
@scottgit thanks for sharing further thoughts. That makes a lot of sense, I'm convinced. However, I suggest that you create another issue to make a feature request for to allow controlling at the ruleset or selector level, since technically that isn't mutually exclusive to this feature. In other words, if this is implemented exactly as requested in this issue (with the option to globally merge, or not merge), then a user such as yourself might choose to always keep the feature turned off. But there are other users who would keep it turned on, since there are plenty of use cases where it wouldn't be necessary to specify at the ruleset level whether or not properties should be merged. So let's keep this feature simple, and ideally have another feature request that augments this with more granular control. |
This is still not implemented. |
+1 |
1 similar comment
+1 |
+1 |
Btw, since there was some debate in this thread: at the very least, adjacent duplicate selectors can safely be merged, which is the example given at the top of the discussion. Non-adjacent duplicate selectors cannot safely be merged by default (but could via an option). |
That's the whole point. |
Well, by now adjacent selectors are combined if you compile with |
I often find myself avoiding mixins because I know that the compiled CSS will have duplicate selectors, which makes for a larger file. For example, a reduced test case:
When this is compiled, the resulting output is:
In a perfect world, selectors inside a mixin and selectors inside the scope in which the mixin was executed would be combined when they are identical. Then, the resulting output would be the much cleaner:
The text was updated successfully, but these errors were encountered: