-
Notifications
You must be signed in to change notification settings - Fork 711
[css-nesting] Conflicts in proposal with Sass/Less #2937
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
Comments
One second thought, I do have a proposal. I've been tinkering with a styling language that avoids the problem of As in: .component {
:hover {} // .component:hover
.modifier{} // .component.modifier
> .child, >> .grandchild {} // .component > .child, .component .grandchild
+ .component {} // .component + .component
} This doesn't address placing the inherited / parent selector after the nested selector, but is that very CSS-y anyway? That's certainly not how the nested It also doesn't necessarily solve at all how Sass/Less would produce the above output, but at least it avoids entirely the semantic confusion of borrowing |
And to answer the question of how to handle the above on the pre-processing side, I imagine Less would do something like a compile flag to support nesting and force .component {
:hover { a: b; }
&:hover { a: b; }
} Would produce the following output (with nested output flag on for Less compiler): .component {
:hover {
a: b;
}
}
.component:hover {
a: b;
} That's much easier to support than trying to decide which |
On the other hand, as expressed in the previous thread, the Sass maintainers consider that syntax (building up a single simple selector thru concatenation of characters) to have been a serious mistake that they wish they could undo. @chriseppstein explicitly stated that he's happy that CSS Nesting is rejecting this possibility. Stepping away from the argument-from-authority, tho, that syntax is also intrinsically ambiguous. There's no way to tell, given a selector like
Unfortunately, this doesn't solve the entire reason I have the " Also, this proposal is even further away from current preprocessor syntax, so I don't think it satisfies your original goal either. |
Would it be possible to satisfy the ambiguity of the BEM case with a function variant.
yeilds
|
AFAIK, the Less maintainers do not. 🤷♂️
I don't disagree. As I said, class name manipulation is best left up to a CSS preprocessor. CSS should deal with complete selectors.
That was kind of my point. Echoing the syntax of preprocessors but producing a different outcome is semantically confusing. It would be the same if CSS had adopted Don't get me wrong. All the CSS preprocessing languages take risks every time syntax is invented that's co-mingled with regular CSS, and that's not necessarily the CSS WG's responsibility to avoid it. I'm just calling for pragmatism, and helping provide an avenue for preprocessors to actually support native nesting, if adopted. The way the proposal sits now, it's not really possible to support it in the preprocessor, which, while not your problem, perhaps unnecessarily limits the goal of it actually being used. And while I'm an advocate of Less, to me |
To be clear, I think native nesting in CSS is not a bad idea. I'm just hoping it can be introduced in a way that isn't incompatible with a lot of existing stylesheets out there. |
Sure, which is why "argument from authority" wasn't the whole point. ^_^
Ah, but Nesting doesn't do that. The intersection of Nesting and Sass syntax produces the same result in both (modulo some details of specificity), except when concatenation comes into play. (Because Sass designed their syntax well, not because of any concerted effort at matching them from me.) If you're ignoring concatenation, then I'm unsure what your objection is. And if this is your concern, then your proposal also fails your criteria, because its intersecting syntax (in particular, stuff like |
It does, currently. It's just easier to polyfill (i.e. flag) that difference in behavior than a native I guess my thinking is this: say at some point at X time in the future, CSS nesting comes to pass. Stylesheet author comes to Sass/Less/PostCSS and says, "Okay, I've written these nested rules, and I know I wrote That said......... maybe the inclusion of Ideally, though, the feature just wouldn't use |
Preprocessors can change. Preprocessor syntax can be deprecated and transformed, often automatically. Browser specs are forever. Toolmakers need to keep the long view here. Authors deserve to have the best syntax that can be provided natively by browsers. Tools like Sass and Less have a much shorter half-life and need to get out of the way when the advances that we've championed become welcomed standards. The cows are the authors, not the tools. Build tools like Sass and Less are the cowpaths. Pave the path. |
@chriseppstein Fair. Is this the best syntax though? I don't know. I feel like you and I have made different points about The idea (nesting) is sound. The cowpath is maybe the right cowpath, but maybe it's not the right paving stones, so to speak. I just want to make sure the door is open for exploration of a better solution, instead of seeing the problem (lack of nesting) and immediately gravitating to just one implementation that addresses the problem, just because we're used to seeing that solution as being "the one" that addresses that problem. That's how I feel about the
Basically this ^^. The historical syntax that Sass/Less (and now PostCSS plugins) have used should be set aside, with a fresh look at the problem. What's most relevant is that those tools identify the problem. Starting with the problem, from square A, what is the most appropriate syntax solution? I don't know that anyone can say what that is yet. |
Just a comment to add to this issue, in case someone comes across this. Related to:
Having spent the last year re-writing a Less parser that extends a valid CSS parser (and having to deeply study more of the CSS spec to do so) I now agree with this statement by @tabatkins and more of the points made here about grammatical ambiguity. Both Less & Sass parsing have unfortunate amounts of ambiguity (and exacerbates some unfortunate CSS grammatical ambiguity) due to nesting syntax, not just what |
Current spec is close to perfect. I would probably make If authors of CSS preprocessors want to allow mixing of the native CSS nesting and SCSS-like nesting in one file, they could rely on |
On the topic of confusion, it might be worth adding some examples or discussion directly into the spec to clarify the limitations of the nesting selector not building up simple selectors as some pre-processors do. In particular, there is a line in the spec which can be read in different ways, and might give the impression that it is possible to do, specifically:
I had to read that a few times to understand what it was saying, and it's the only place in the spec that does not include a space after the nesting selector. |
A number of examples don't have a space after the nesting selector, such as Examples 2, 4, and 7. |
True, I should have been more specific. Those examples contain syntax like
I think that could be useful to include, given that it is valid in preprocessors, and some people may expect that it's valid in css-nesting as well. |
As far as I understand, your example is valid and equals to:
It is different from Sass, but it is probably more logical. |
For reference, the Sass team has documented exactly where things differ, and how we plan to handle the migration.
While I find it a bit funny to relegate specificity differences to a parenthetical -- authors care a lot about that little detail! -- I do think those differences will be rare, and easy to draw attention to. |
Please don't make It can be a differentiating factor for preprocessors. If the rule has I suspect people will make |
This is a good point / strategy. |
@matthew-dean that is how Sass plans on doing things. At least in the short term. |
Wrt character concatenation, we're explicitly rejecting that use-case, as explained earlier in this thread. Wrt overlapping/clashing with existing preprocessor syntax, the Sass maintainers, at least, have told us not to worry about it, and they'll engineer around any remaining difficulties. I'm going to assume that other preprocessors will end up in a similar situation if they're not already. Closing as Invalid/Wontfix. |
Note: I originally posted this on another thread, and was asked to re-post as a new issue.
I worry that the use of & in the CSS nesting proposal is going to lead to a lot of confusion, since it doesn't work like Sass's / Less's &. So half your code may need to be flattened, and half can maybe preserve &. When writing in Sass or Less, how do you target which is which? The preprocessing languages don't lose all usefulness, so both of these ecosystems, if this were adopted, would have to re-invent their entire & syntax / usage if people want to target nested selectors as output. Which is a shame, because that would slow adoption and probably lead more to reject using this feature.
I don't have a better syntax suggestion, but I also don't see this (native CSS nesting) as necessary. But, obviously as a Less contributor, I'm biased.
Most "best-practice" style-writing I've seen suggests not really nesting at all, but to use single class identifiers in a BEM-way, like:
This keeps things organized and provides single class matching for the browser. But this isn't the way the nesting proposal works. I do get why adopting that form (partial class appending) would be rejected by a CSS spec, because CSS is looking to define complete selector matching, but that just points to a preprocessor still being relevant, which points to a potential conflict around & usage and output. I think a different syntax is needed.
The text was updated successfully, but these errors were encountered: