Skip to content

Commit

Permalink
Update handling of root selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jul 29, 2024
1 parent f882fe4 commit 4aa1c66
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/block-editor/src/utils/transform-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,23 @@ function transformStyle(
prefix: wrapperSelector,
exclude: [ ...ignoredSelectors, wrapperSelector ],
transform( prefix, selector, prefixedSelector ) {
// `html`, `body` and `:root` need some special handling since they
// generally cannot be prefixed with a classname and produce a valid
// selector.
if ( selector.includes( 'body' ) ) {
return selector
.replace( /:root :where\(body\)/g, prefix )
.replace( /:where\(body\)/g, prefix )
.replace( 'body', prefix );
}
if ( selector.startsWith( ':root' ) ) {
return selector.replace( ':root', prefix );
}
if ( selector.startsWith( 'html' ) ) {
return selector.replace( 'html', prefix );
}
// Avoid prefixing an already prefixed selector.
if ( selector.startsWith( prefix ) ) {
return prefixedSelector.replace(
`${ prefix } ${ prefix }`,
prefix
);
}
return prefixedSelector;

// `html`, `body` and `:root` need some special handling since they
// generally cannot be prefixed with a classname and produce a valid
// selector.
// Also include some special rules for various forms of :root and body
// that crop up.
return selector
.replace( /:root :where\(body\)/g, prefix )
.replace( /:where\(body\)/g, prefix )
.replace( /^(html|body|:root)/, prefix );
},
} ),
baseURL && rebaseUrl( { rootUrl: baseURL } ),
Expand Down

0 comments on commit 4aa1c66

Please sign in to comment.