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

postcss-nesting: nested conditionals #1368

Merged
merged 3 commits into from
Apr 21, 2024

Conversation

romainmenke
Copy link
Member

see : w3c/csswg-drafts#8738 (comment)

::before, ::after {
	color: blue;

	@media screen { color: cyan; }
}

Is now equivalent to :

::before, ::after {
	color: blue;

	@media screen {
		@nest {
			color: cyan;
		}
	}
}

Where @nest represents the parent rule and its selector directly.
There is no wrapping in :is().

@nest doesn't take any arguments/params.

@nest is not sure to remain as its value as an author writeable rule is questionable. Because of this I didn't want to add support for this new @nest just yet. We can transpile to unnested CSS without it.

Verified

This commit was signed with the committer’s verified signature.
romainmenke Romain Menke

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…9b3fe
### Unreleased (patch)

- Edition `2024-02`:
- Do not rewrite selectors for declarations in conditional rules to a form with `:is()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indent intentional?

Also, I assume you want to patch this after the major?

Copy link
Member Author

@romainmenke romainmenke Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the major.

This is a minimally breaking change.
(Any change theoretically is a breaking change for someone.)

It is only breaking when having something like this :

a, .link {
  @media (min-width: 64rem) {
    color: blue;
  }
}

a {
  color: red;
}

Before this change blue would have specificity [0, 1, 0] because of :is() and would overrule red.

After this change blue will have specificity [0, 0, 1] and red will have win because it appears later.

So it only affects declarations in nested conditionals that became more specific as a result of :is() and had lower specificity declarations appearing after it.

User that do depend on the :is() behavior would need to opt-in by writing :

a, .link {
  @media (min-width: 64rem) {
    & {
      color: blue;
    }
  }
}

a {
  color: red;
}

Chrome had a use counter for this and other patterns that would be affected by this change as the result was extremely low:

CSSNestedGroupRuleSpecificity (0.00017%), which triggers when @nest-wrapping bare declarations within a nested group rule would make a difference to the cascade. Making this move would allow nesting e.g. @media in pseudo-element rules, which doesn't work currently since we're wrapping in an &-rule.

I am sure that our users will have a higher number (Chrome doesn't see what we transpile away) but hoping that the pattern is still sufficiently rare.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, makes sense!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indent intentional?

Forgot to address this

This change is specific to that edition.
It doesn't affect the plugin as a whole.

That indent will make it a nested (no pun intended) list item.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…9b3fe
@romainmenke romainmenke merged commit c74cb2b into main Apr 21, 2024
7 checks passed
@romainmenke romainmenke deleted the postcss-nesting--affectionate-squirrel-9f9319b3fe branch April 21, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants