Open tabatkins opened 2 years ago
We have so many at rules today. It does need a good mechanism to detect if they are supported or not.
This is relevant for browsers that want to ship style container queries, along with a feature query for testing support. I left more details in https://github.com/w3c/csswg-drafts/issues/6175#issuecomment-1232179302, but I think thread this is actually the proper place to make progress on the issue.
Would it be ready to bring back as a proposal with agenda+, or is there more discussion that needs to happen here? @tabatkins summary above looks reasonable to me, and better than one-offs like the @supports container()
syntax that we approved in the other thread.
/cc @lilles
Agenda+ to see if we can get this resolved, and/or get concrete feedback on the proposal.
The CSS Working Group just discussed At-rule Prelude Tests
.
@emilio after the meetings, you mentioned it might be possible to do strict parsing of query syntaxes inside @supports
- eg failing on unknown queries? Does that seems like a viable approach that doesn't require too much special casing?
@emilio after the meetings, you mentioned it might be possible to do strict parsing of query syntaxes inside
@supports
- eg failing on unknown queries? Does that seems like a viable approach that doesn't require too much special casing?
Could we make <general-enclosed>
and parts of media/container queries that are unknown, including unrecognized media type fail the @supports at-rule()
query?
We resolved on a similar behavior for forgiving selectors for @supports selector()
.
Agenda+ to see if we can resolve on @lilles suggestion above. I think it would be a significant improvement, if we can do it.
Sorry, I was over-eager putting this on the agenda. It looks like where we left off after TPAC, we still need to re-form the basic proposal - and then we can include this update to the proposal.
I’m seeing an uptick in requests from authors for this (E.g. [1], [2], [3], but there are more). One thing that dawned on me is that style queries is another special case here because of the style()
function, which is not a prelude.
Of the three parsing forms proposed by Tab, the 2nd one would allow checking that.
Also, naively the first and second forms collide grammar-wise; we tell them apart by always invoking the first form when the only non-WS contents of the function are a single at-keyword token.
What if we renamed that one to at-rule-name()
? It’s fine to rename, as nothing of this is specced yet and nobody’s shipping this.
I’m also fine with dropping the third proposed form here, and have authors test either only the at-rule’s name or an actual full rule. It would prevent that potential ;
syntax-collision
Oh wow I forgot about this issue when I opened https://github.com/w3c/csswg-drafts/issues/10829
If the property in @position-try
contains !important
, what should the result return?
CSS.supports(`at-rule(@position-try; inset: 20px)`) // => true
CSS.supports(`at-rule(@position-try; inset: 20px !important)`) // => true or false?
It is invalid to use !important on the properties in the
. Doing so causes the property it is used on to become invalid, but does not invalidate the @property-try rule as a whole. https://drafts.csswg.org/css-anchor-position-1/#accepted-position-try-properties
In #2463 we just resolved to add
at-rule(@foo)
andat-rule(@foo; desc: value)
functions to @supports, to test for whether an at-rule is supported at all, and whether it supports a givendesc: value
declaration.It was brought up in the call (and deferred for time) that we should be able to test for support of things in an at-rule's prelude as well, as that can sometimes be significant and potentially change over time. (Especially for at-rules that end in a semicolon instead of a block, as they're nothing but prelude.)
An important point brought up by @emilio (and supported with historical design context by @dbaron) is that part of the "no special-casing needed, It Just Works" feature of @supports is that we can use it to tell if something is dropped as a whole easily, but can't easily test whether some part of a construct is dropped (since that information is not currently signaled by the CSS parsers, and even if parsers are instrumented to flag a parse error, it's possible to miss spots and thus have @supports give an incorrect result).
In the case of preludes, this isn't a problem - they're either supported or invalidate the at-rule as a whole. Thus, adding detection support for them is possible. The question is just how precisely to invoke this.
To avoid any special-casing at all, I suggest we do support passing an entire at-rule in the function, but we just test whether the at-rule as a whole is dropped or not. That is,
at-rule(@foo bar baz {...})
(orat-rule(@foo bar baz)
for semicolon-ended rules) is allowed, and just detects whether the rule, when parsed, is dropped or not. We do the parsing as if it was the first content in a stylesheet, soat-rule(@import "foo")
would return true.We thus would have three parsing forms for the at-rule function:
at-rule(@foo)
, which returns whether this is a recognized at-rule name at all. (This doesn't invoke any parsing, but afaik all existing impls do keep up lists of all their recognized at-rules, so this should still be a no-special-case easy check without the possibility of drifting out of sync.)at-rule(@foo bar {baz: qux})
, which returns whether or not the at-rule as a whole, when parsed as the first and only content in a fresh stylesheet, is valid or dropped. If the at-rule is valid but drops some of its contents as invalid, such as an unknown descriptor, this will still return true.at-rule(@foo; desc: value)
, which returns whether the at-rule is recognized, and the given descriptor successfully parses as part of that at-rule. This should be testable by invoking existing parsing functions in a relatively generic fashion.Some implications:
at-rule(@counter-style foo {})
will fail, because @counter-style requires the 'system' descriptors and either 'symbols' or 'additive-symbols', or else the whole rule is dropped.desc:value
after it), but allowing it as a valid second-form invocation is a small wrinkle in parsers. I'm fine either way.