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

Reset specificity of body selector when processing with postcss. #60266

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/block-editor/src/utils/transform-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function transformStyle(
return css;
}

const postcssFriendlyCSS = css.replace( ':where(body)', 'body' );
Copy link
Contributor

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?

Copy link
Contributor Author

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 😅

try {
return postcss(
[
Expand All @@ -31,7 +32,7 @@ function transformStyle(
} ),
baseURL && rebaseUrl( { rootUrl: baseURL } ),
].filter( Boolean )
).process( css, {} ).css; // use sync PostCSS API
).process( postcssFriendlyCSS, {} ).css; // use sync PostCSS API
} catch ( error ) {
if ( error instanceof CssSyntaxError ) {
// eslint-disable-next-line no-console
Expand Down
Loading