-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Reset specificity of body selector when processing with postcss. #60266
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +14 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! This is testing nicely for me, and I notice that other :where(body ...
related rules are unaffected (e.g. base layout styles), so I didn't run into any issues with it.
Would it be worth adding a test to the test file for this function? Since it can be thrown a variety of CSS, I'm wondering if it's possible for there to be peculiar edges cases 🤔
Since this fixes quite a visible bug, I won't let those comments hold up getting this in, though.
LGTM!
@@ -19,6 +19,7 @@ function transformStyle( | |||
return css; | |||
} | |||
|
|||
const postcssFriendlyCSS = css.replace( ':where(body)', 'body' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would :where(body)
ever be chained after another rule, i.e. .my-class-name:where(body)
? If so, the result might not be valid CSS. I imagine that would be very edge-case territory as it's probably quite unlikely anyone would do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah I'm not sure that will be much of a problem, because any unchanged selector with :where(body)
would get the scoping selector prepended to it, so it would only work if the scoping selector happened to be attached to the html
element. That's pretty unlikely to happen 😅
Thanks for reviewing @andrewserong!
Yeah might be worth doing, but good idea to do it as a follow-up! |
…dPress#60266) Co-authored-by: tellthemachines <[email protected]> Co-authored-by: andrewserong <[email protected]>
What?
Fixes a bug introduced in #60106, in which global styles selectors were wrapped in
:where()
to reduce their specificity.When the editor isn't iframed, its styles are wrapped in a scoping selector using this postcss plugin . The plugin is smart enough to recognise and replace root selectors such as
body
andhtml
, but it doesn't work for:where(body)
.To fix this, we can replace any occurrences of
:where(body)
withbody
before feeding them into postcss. (We don't seem to usehtml
for global styles which is why I haven't added it.)Testing Instructions
.editor-styles-wrapper
: