sass-site/source/documentation/breaking-changes/bogus-combinators.liquid

68 lines
2.4 KiB
Plaintext
Raw Normal View History

---
2023-05-26 00:24:38 +02:00
title: 'Breaking Change: Invalid Combinators'
introduction: >
Sass has historically been very permissive about the use of leading, trailing,
and repeated combinators in selectors. These combinators are being deprecated
except where they're useful for nesting.
---
2023-05-26 20:32:08 +02:00
{% markdown %}
2023-05-31 18:02:42 +02:00
Sass has historically supported three invalid uses of combinators:
2023-05-31 18:02:42 +02:00
* Leading combinators, as in `+ .error {color: red}`.
2023-05-31 18:02:42 +02:00
* Trailing combinators, as in `.error + {color: red}`.
2023-05-31 18:02:42 +02:00
* Repeated combinators, as in `div > > .error {color: red}`.
2023-05-31 18:02:42 +02:00
None of these are valid CSS, and all of them will cause browsers to ignore the
style rule in question. Supporting them added a substantial amount of
complexity to Sass's implementation, and made it particularly difficult to fix
various bugs related to the `@extend` rule. As such, we [made the decision] to
remove support for these uses.
2023-05-31 18:02:42 +02:00
[made the decision]: https://github.com/sass/sass/issues/3340
2023-05-31 18:02:42 +02:00
**There is one major exception**: leading and trailing combinators may still
be used for nesting purposes. For example, the following is still very much
supported:
2023-05-26 20:32:08 +02:00
{% endmarkdown %}
2023-05-26 20:32:08 +02:00
{% codeExample 'bogus-combinators' %}
2023-05-31 18:02:42 +02:00
.sidebar > {
.error {
color: red;
}
}
2023-05-31 18:02:42 +02:00
===
.sidebar >
.error
color: red
{% endcodeExample %}
2023-05-26 20:32:08 +02:00
{% markdown %}
2023-05-31 18:02:42 +02:00
Sass will only produce an error if a selector still has a leading or trailing
combinator _after nesting is resolved_. Repeated combinators, on the other
hand, will always be errors.
2023-05-31 18:02:42 +02:00
To make sure existing stylesheets who (likely accidentally) contain invalid
combinators, we'll support a transition period until the next major release of
Dart Sass.
2023-05-31 18:02:42 +02:00
## Transition Period
2023-06-01 22:56:54 +02:00
{% compatibility 'dart: "1.54.0"', 'libsass: false', 'ruby: false' %}{% endcompatibility %}
2023-05-31 18:02:42 +02:00
First, we'll emit deprecation warnings for all double combinators, as well as
leading or trailing combinators that end up in selectors after nesting is
resolved.
2023-05-31 18:02:42 +02:00
{% render 'documentation/snippets/silence-deprecations' %}
2023-05-31 18:02:42 +02:00
In addition, we'll immediately start omitting selectors that we know to be
invalid CSS from the compiled CSS, with one exception: we _won't_ omit
selectors that begin with a leading combinator, since they may be used from a
nested `@import` rule or `meta.load-css()` mixin. However, we don't encourage
this pattern and will drop support for it in Dart Sass 2.0.0.
2023-05-26 20:32:08 +02:00
{% endmarkdown %}