Re: [csswg-drafts] [css-nesting] Another problem with mixing declarations and rules - error recovery (#8349)

> Yes, Romain is making the right point. While an @layer rule in an old browser won't mess up the following rule, it will absolutely make your stylesheet useless since it'll cause the entire contents of the @layer to get thrown away. That's a huge problem! There's simply no way to get around it, tho, without at best doing some really awkward workarounds in the design that would significantly hamper the feature going forward.

I'm not advocating for some workaround that will make nested rules work in an older browser, and of course I'm aware that a stylesheet that's naively written for a browser that supports nesting isn't going to give a good result in an older browser. That's not my point.

> Nesting is in exactly the same boat. Your nested rules will simply get thrown away in older browsers. There's no way to work around this; you have to either buy in to Nesting (accepting that your stylesheet will be broken in older browsers) or avoid it entirely. And if you're buying in, the error-recovery change doesn't matter; it'll work correctly in the browsers that your stylesheet works in, and it'll be extremely broken in older browsers no matter what.

My point is that while stylesheets will break in older browsers, they should break in a predicable way so that anyone who wants to provide fallback behavior for older browsers can. This is a fundamental aspect of CSS as you're well aware. Saying 'it's partly broken, so who cares *how* broken" is not generally the right answer.

The behavior of swallowing the first declaration after a nested rule will be surprising to most authors.

> This is just how adding newer syntax features works. It's happened in the past, and it'll happen in the future; Nesting is perfectly normal in this regard. It's awkward during the transition period but stops being a problem as usage numbers advance. We certainly prefer designing features that can gracefully fallback instead, but if sometimes isn't an option.

The transition period is important. If we don't provide a functional mechanism to support both older and newer browsers, it will hurt the uptake of the feature until the vast majority of browsers support it.

Of course due to the nature of nesting an 'all-or-nothing' approach probably makes the most sense for most authors. To this end, we need to make sure that nesting is feature detectable so that authors can include both smaller stylesheets that use nesting, and larger ones that don't for older clients. (I expect preprocessors to generate both from a single source.)

That doesn't mean that we should ignore fallback behavior, CSS isn't versioned.

> All that said, this particular issue only occurs if you put properties after rules, which is a bad practice anyway. Put all your properties at the top, before any rules, and you'll be fine. Putting them later gives you absolutely nothing except possible confusion.

Agreed, but if this is the approach that we take (as listed as option 3 above), at a minimum we need to document putting properties first as best practice and explain to author what will happen if they don't. We just spent a large part of a meeting discussing how mixed rules and properties work, and no one said "don't do that".

We also need to take this aspect into consideration when we consider alternatives.



-- 
GitHub Notification of comment by plinss
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8349#issuecomment-1405724040 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 26 January 2023 21:58:23 UTC