Skip to content
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

Behavior of "unknown " media feature name/value #35435

Open
mdubet opened this issue Aug 11, 2022 · 3 comments
Open

Behavior of "unknown " media feature name/value #35435

mdubet opened this issue Aug 11, 2022 · 3 comments

Comments

@mdubet
Copy link
Contributor

mdubet commented Aug 11, 2022

Media Queries Level 3/4/5 have a consistent description of the way to handle unknown media feature name or unknown media feature value: transform the media query to not all.

An unknown or , or disallowed , results in the value "unknown". A whose value is "unknown" must be replaced with not all.

(quote from https://drafts.csswg.org/mediaqueries-5/#error-handling)

With the introduction of the new <general-enclosed> term in the grammar and the 3-valued logic evaluation, and the intention of allowing future-proof query matching in the case of unknown media feature, my understanting of the spec would be that:

  • when one (or several) media feature name or value is unknown, and the complete media query is unknown, such as (width: foobar) (unkown value) or (foobar) (unknown name), it should be replaced with not all.
  • when one (or several) media feature name or value is unknown, but the complete media query is either true or false, it should not be replaced such as (foobar: foobarvalue) or (color) (assuming color is true).

However, the WPT media queries tests rely on another behavior:

return match.media == query;

Even when the media query result is unknown, they don't expect it to be replaced by not all. Is this a bug ?

Current implementations

The implementations in Firefox and Chrome have different behaviors on this issue.

Firefox Developer Edition (v104):

> window.matchMedia("(scan: foobar)")
> MediaQueryList { media: "not all", matches: false, onchange: null }

> window.matchMedia("(foobar: none) or (color)")
> MediaQueryList { media: "not all", matches: false, onchange: null }

In Chrome Canary:

> window.matchMedia("(scan: foobar)")
> MediaQueryList {media: '(scan: foobar)', matches: false, onchange: null}

> window.matchMedia("(foobar: none) or (color)")
> MediaQueryList {media: '(foobar: none) or (color)', matches: true, onchange: null}
@gsnedders
Copy link
Member

An unknown or , or disallowed , results in the value "unknown". A whose value is "unknown" must be replaced with not all.

(quote from https://drafts.csswg.org/mediaqueries-5/#error-handling)

w3c/csswg-drafts#7585 clarified the the spec text here:

An unknown <<mf-name>> or <<mf-value>>, or a feature value which does not matches the value syntax for that media feature, results in the value “unknown”. A <<media-query>> whose value is “unknown” must be replaced with ''not all''.

I think this makes it pretty clear that Firefox is right here? cc @andruud, given you changed away from this

@mdubet
Copy link
Contributor Author

mdubet commented Aug 11, 2022

I think Firefox is right when the media query is unknown (1st example), but not when it's definitely true or false because of 3-value boolean logic (2nd example).

@gsnedders
Copy link
Member

Oh, yeah, I guess there's still plenty unclear here: w3c/csswg-drafts#7595

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants