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

[css-nesting] Define how relative selectors serialize. #8970

Closed
emilio opened this issue Jun 15, 2023 · 7 comments
Closed

[css-nesting] Define how relative selectors serialize. #8970

emilio opened this issue Jun 15, 2023 · 7 comments
Labels
Closed Accepted by CSSWG Resolution css-nesting-1 Current Work Tested Memory aid - issue has WPT tests

Comments

@emilio
Copy link
Collaborator

emilio commented Jun 15, 2023

https://drafts.csswg.org/css-nesting/#syntax says that you're supposed to parse relative selectors while nesting.

However it doesn't say anything about how to serialize them.

<!doctype html>
<style>
  .foo {
    +bar {
      color: green;
    }
  }
</style>
<script>
  console.log(document.styleSheets[0].cssRules[0].cssRules[0].cssText);
</script>

Blink and WebKit serialize the selector as written (so, + bar).

That's ok, I suppose, but I tend to think it'd be more useful if it serialized to the expanded form (& + bar). That means that .cssText, .selectorText, etc are always valid, independently of whether the rule is a nested style rule or not. So you can always do oneRule.selectorText = anotherRule.selectorText.

Thoughts?

@emilio
Copy link
Collaborator Author

emilio commented Jun 15, 2023

cc @sesse @andruud @mdubet

@emilio
Copy link
Collaborator Author

emilio commented Jun 15, 2023

I guess you could argue the same for nested implicit rules.

So:

.foo {
  @media (min-width: 10px) {
    color: green;
  }
}

The media rule's cssText might want to contain the & { color: green } rather than hide it.

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 16, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1835068
gecko-commit: dbe4f23432a64d66113d4ae1656844cc498e5011
gecko-reviewers: dshin
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 17, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 18, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1835068
gecko-commit: dbe4f23432a64d66113d4ae1656844cc498e5011
gecko-reviewers: dshin
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Jun 18, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125

UltraBlame original commit: dbe4f23432a64d66113d4ae1656844cc498e5011
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Jun 18, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125

UltraBlame original commit: dbe4f23432a64d66113d4ae1656844cc498e5011
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Jun 18, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125

UltraBlame original commit: dbe4f23432a64d66113d4ae1656844cc498e5011
ErichDonGubler pushed a commit to ErichDonGubler/firefox that referenced this issue Jun 19, 2023
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125
@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-nesting] Define how relative selectors serialize., and agreed to the following:

  • RESOLVED: Nested relative selectors serialize with the (implied) nesting selector
  • RESOLVED: Grouping rules with direct styles serialize them with the (implied) style rule around them.
The full IRC log of that discussion <TabAtkins> emilio: Our impl does something different from wk/blink
<TabAtkins> emilio: I prefer ours
<TabAtkins> emilio: blink/wk serialize relative selectors as written
<TabAtkins> emilio: [missed example]
<TabAtkins> emilio: In firefox we add the nesting selector at parse time, so we serialize it as well
<astearns> example in issue
<TabAtkins> emilio: the spec isn't clear. i have a slight preference for firefox, because selectorText works regardless of whether your'e nesting or not
<TabAtkins> emilio: which I think is a nice property to have - you can set selectorText to that of another rule regardless
<TabAtkins> I'm happy to specify firefox's behavior, fwiw
<fantasai> +1 for consistent output
<TabAtkins> emilio: this should probably also apply to the implicit style rule we add when we define nested properties in a grouping rule
<TabAtkins> +1
<TabAtkins> astearns: concerns?
<TabAtkins> [none]
<TabAtkins> proposed resolution: nested relative selectors serialize with the implicit nesting selector
<TabAtkins> proposed resolution: and styles in grouping rules serialize with the implied rule around them
<fantasai> +1
<TabAtkins> RESOLVED: Nested relative selectors serialize with the (implied) nesting selector
<TabAtkins> RESOLVED: Grouping rules with direct styles serialize them with the (implied) style rule around them.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-nesting] Define how relative selectors serialize..

The full IRC log of that discussion <TabAtkins> fantasai: I think the second reoslution was about styles directly in a media rule?
<fantasai> TabAtkins: For conditional rules that contain declarations
<TabAtkins> TabAtkins: It's about `.foo { @media (...) { display: block; } }`
<TabAtkins> TabAtkins: the reoslution says this'll serialize with a `& { display: block; }` inside the media
<fantasai> fantasai: But doesn't apply to nested rules, right?
<TabAtkins> TabAtkins: Correct, it doesn't, just to non-style rules
<emilio> s/nested rules/nested style rules
<fantasai> fantasai: Concerned about consistency with nested rules
<fantasai> TabAtkins: this makes the serialization match the OM
<TabAtkins> emilio: Yes, also it makes the cssText valid regardless of nesting status
<TabAtkins> emilio: direct properties dont' parse when the @media isn't nested
<TabAtkins> (well, it parses, but they're discarded)
<TabAtkins> fantasai: makes sense, thanks

@mdubet
Copy link

mdubet commented Jul 12, 2023

I understand the benefit of being able to consistenly use selectorText(), but isn't this change a bit against the "serialize CSS text to the smallest syntactic equivalent" rule ?

@emilio
Copy link
Collaborator Author

emilio commented Jul 12, 2023

Yes, though the "smallest syntactic equivalent" in this case isn't valid in all contexts, so I think it's better to use the longer form since it's the "always valid" form.

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 13, 2023
Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1843349
gecko-commit: 269d9593b265d4e6c2bc0b1a610dc182258d641a
gecko-reviewers: boris
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jul 13, 2023
…nt resolutions. r=boris

Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 14, 2023
Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1843349
gecko-commit: 269d9593b265d4e6c2bc0b1a610dc182258d641a
gecko-reviewers: boris
@tabatkins
Copy link
Member

Ah forgot to tag this issue into the commit message as well, this is fixed in 4810428

@tabatkins tabatkins added Closed Accepted by CSSWG Resolution Tested Memory aid - issue has WPT tests labels Jul 14, 2023
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Jul 16, 2023
…nt resolutions. r=boris

Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518

UltraBlame original commit: 269d9593b265d4e6c2bc0b1a610dc182258d641a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Jul 16, 2023
…nt resolutions. r=boris

Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518

UltraBlame original commit: 269d9593b265d4e6c2bc0b1a610dc182258d641a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Jul 16, 2023
…nt resolutions. r=boris

Update as per the resolutions in
w3c/csswg-drafts#8970, making the
mixed-properties test not tentative.

Differential Revision: https://phabricator.services.mozilla.com/D183518

UltraBlame original commit: 269d9593b265d4e6c2bc0b1a610dc182258d641a
mrobinson pushed a commit to mrobinson/stylo that referenced this issue Mar 1, 2024
Make parsing test not depend on under-specified serialization details,
see w3c/csswg-drafts#8970.

Differential Revision: https://phabricator.services.mozilla.com/D181125
@emilio emilio closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by CSSWG Resolution css-nesting-1 Current Work Tested Memory aid - issue has WPT tests
Projects
None yet
Development

No branches or pull requests

4 participants