Skip to content

Commit

Permalink
Fix all the problems
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jul 29, 2024
1 parent 4aa1c66 commit b7c15d7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/block-editor/src/utils/transform-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import rebaseUrl from 'postcss-urlrebase';

const cacheByWrapperSelector = new Map();

// Ordering is important since `:root` would also match `:root :where(body)`.
const ROOT_SELECTOR_REGEX =
/^(:root :where\(body\)|:where\(body\)|:root|html|body)/;

function transformStyle(
{ css, ignoredSelectors = [], baseURL },
wrapperSelector = ''
Expand All @@ -27,8 +31,12 @@ function transformStyle(
exclude: [ ...ignoredSelectors, wrapperSelector ],
transform( prefix, selector, prefixedSelector ) {
// Avoid prefixing an already prefixed selector.
if ( selector.startsWith( prefix ) ) {
return prefixedSelector.replace(
if (
prefixedSelector.startsWith(
`${ prefix } ${ prefix }`
)
) {
prefixedSelector = prefixedSelector.replace(
`${ prefix } ${ prefix }`,
prefix
);
Expand All @@ -39,10 +47,16 @@ function transformStyle(
// 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 );
if ( ROOT_SELECTOR_REGEX.test( selector ) ) {
return selector.replace(
ROOT_SELECTOR_REGEX,
prefix
);
}

// console.log( out, rootSelector, prefixedSelector );

return prefixedSelector;
},
} ),
baseURL && rebaseUrl( { rootUrl: baseURL } ),
Expand Down

0 comments on commit b7c15d7

Please sign in to comment.