Sass announced there will be some upcoming breaking changes to the syntax in mixed declarations. As of Sass 1.77.7 I’m getting the following warnings when compiling. –
Sass’s behavior for declarations that appear after nested
rules will be changing to match the behavior specified by CSS in an upcoming
version. To keep the existing behavior, move the declaration above the nested
rule. To opt into the new behavior, wrap the declaration in& {}
.
Below is a basic example of the issue. If we define a mixin and then add it to a style class at the top of the class then declare other rules we will receive the above warning in the console.
@mixin border($color) {
border: 1px solid $color;
}
.style-with-mixin {
@include border(red);
padding: 20px;
// ...Any other styles
}
To remove this error we either have to wrap styles like the following –
.style-with-mixin {
@include border(red);
&{
padding: 20px;
// ...Any other styles
}
}
Or shift the mixin to be the last style declaration –
.style-with-mixin {
padding: 20px;
// ...Any other styles
@include border(red);
}
However, both of these solutions involve a lot of rewriting of styles for whole projects which isn’t going to be realistic for me. Other than locking the sass version has anyone been able to find a work around that can be implemented efficiently in exisiting projects?
2
Answers
there is no need to add &{} everywhere
just reorder your lines
make sure props at beginning then the nesting selectors
example this
should be
The problem is even worse when you have mixins that also use nested rules inside. I have no clue how to fix the deprecations then without having multiple selector duplicates in my output css.