Skip to content

Commit

Permalink
Block Editor: Avoid double-wrapping selectors when transforming the s…
Browse files Browse the repository at this point in the history
…tyles (#54981)

* Block Editor: Avoid double-wrapping selectors when transforming the styles
* Include space in the check
  • Loading branch information
Mamaduka committed Oct 3, 2023
1 parent bb8a3b9 commit 4ca991d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
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

1 comment on commit 4ca991d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4ca991d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6388437149
📝 Reported issues:

Please sign in to comment.