Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

[css-cascade-6] fix @import definition - #14419

#14419
Open
romainmenke wants to merge 1 commit into
w3c:mainw3c/csswg-drafts:mainfrom
romainmenke:patch-5romainmenke/csswg-drafts:patch-5Copy head branch name to clipboard
Open

[css-cascade-6] fix @import definition#14419
romainmenke wants to merge 1 commit into
w3c:mainw3c/csswg-drafts:mainfrom
romainmenke:patch-5romainmenke/csswg-drafts:patch-5Copy head branch name to clipboard

Conversation

@romainmenke

@romainmenke romainmenke commented Aug 31, 2026

Copy link
Copy Markdown
Member

see: #13698

By the current definition:

media-import-condition = <media-query-list>

media-query-list = <media-query>#

So removing the ? in the @import syntax definition made a media query required as # is one or more.

@cdoublev

cdoublev commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

To parse a <media-query-list> production, parse a comma-separated list of component values, then parse each entry in the returned list as a <media-query>. Its value is the list of <media-query>s so produced.

Note: This definition of parsing intentionally accepts an empty list.

https://drafts.csswg.org/mediaqueries-5/#mq-syntax

@romainmenke

Copy link
Copy Markdown
Member Author

But that isn't reflected in the syntax definition.
Maybe it should be?

A conditional <media-import-condition> in @import makes it possible to use that definition in linters. Otherwise such linters flag @import 'foo.css' as invalid.

@cdoublev

cdoublev commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

I have no opinion on whether this should be reflected in the syntax. But I prefer that a superfluous ? not be added if an empty input is also defined as valid in prose.

<forgiving-selector-list> and <media-query-list> are the only two productions that accept an empty input, if I am not mistaken. To accomodate linter's needs while considering my opinion, an alternative could therefore be to redefine how they are parsed, and add ? wherever it is needed. E.g. @media {} is valid and @media is currently defined with @media <media-query-list> {...}.

Note that :is() is generally defined to match : <function-token> <any-value> ) before being validated/parsed against :is(<forgiving-selector-list>). <any-value> does not accept an empty input while <forgiving-selector-list> does, and all browsers currently accept an empty :is().

@romainmenke

romainmenke commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

I think that in this case author needs go before technical purity :)
I also think that if something can be trivially expressed in a syntax definition that we should always do that.

Other than that I don't have any preference as to how or where we fix this.

@cdoublev

cdoublev commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

I tend to agree with you because spec authors can make mistake such as @custom-media <extension-name> [ <media-query-list> | true | false ] ;: I do not think @custom-media --name; is intended to be valid, so it should be @custom-media <extension-name> [<media-query-list> | true | false]! ;.

I will work on an alternative PR later, if that works for you.

@romainmenke

Copy link
Copy Markdown
Member Author

That would be great, thank you so much 🙇

@cdoublev

cdoublev commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

I preferred to open #14431 since it seems more complicated than I thought, for the reasons explained in this issue.

@romainmenke

Copy link
Copy Markdown
Member Author

Thank you @cdoublev 🙇

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.