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

Block Editor: Avoid double-wrapping selectors when transforming the styles #54981

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ color: red;
}"
`;

exports[`CSS selector wrap should not double wrap selectors 1`] = `
".my-namespace h1,
.my-namespace .red {
color: red;
}"
`;

exports[`CSS selector wrap should replace :root selectors 1`] = `
".my-namespace {
--my-color: #ff0000;
}"
`;

exports[`CSS selector wrap should replace root tags 1`] = `
".my-namespace,
.my-namespace h1 {
Expand Down Expand Up @@ -49,9 +62,3 @@ color: red;
}
}"
`;

exports[`CSS selector wrap should replace :root selectors 1`] = `
".my-namespace {
--my-color: #ff0000;
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ describe( 'CSS selector wrap', () => {

expect( output ).toMatchSnapshot();
} );

it( 'should not double wrap selectors', () => {
const callback = wrap( '.my-namespace' );
const input = ` .my-namespace h1, .red { color: red; }`;

const output = traverse( input, callback );

expect( output ).toMatchSnapshot();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const wrap =
return selector;
}

// Skip the update when a selector already has a namespace + space (" ").
if ( selector.trim().startsWith( `${ namespace } ` ) ) {
return selector;
}

// Anything other than a root tag is always prefixed.
{
if ( ! selector.match( IS_ROOT_TAG ) ) {
Expand Down
Loading