Make WordPress Core

Opened 7 weeks ago

Closed 9 days ago

Last modified 9 days ago

#61769 closed defect (bug) (fixed)

Global Styles: Prevent empty CSS rules and malformed selectors for custom css for blocks

Reported by: aaronrobertshaw's profile aaronrobertshaw Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.6.2 Priority: normal
Severity: normal Version: 6.6
Component: Editor Keywords: gutenberg-merge has-patch has-unit-tests has-testing-info commit fixed-major dev-reviewed
Focuses: Cc:

Description (last modified by hellofromTonya)

This ticket tracks the merging of PHP files for the following Gutenberg changes:

These changes fix two issues with the generation of custom css for blocks with Global Styles.

  1. Empty CSS rules e.g. :root :where(.wp-block-heading){}
  2. Malformed pseudo element selectors :root :where(.wp-block-heading::before)

Change History (17)

This ticket was mentioned in PR #7097 on WordPress/wordpress-develop by @aaronrobertshaw.


7 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Syncs the changes from https://github.com/WordPress/gutenberg/pull/63980

These updates include the PHP fixes for empty CSS rules and invalid selectors for Global Styles custom CSS for blocks.

Please note: JS package updates will be required to resolve the issue in the editor.

#### Testing Instructions

  1. In the site editor navigate to Styles > Blocks > Heading > Advanced
  2. Add the following into the Custom CSS field: &::before { content: 'Foo' }
  3. Ensure the page being edited has a heading block
  4. Save and view the frontend
  5. Confirm the heading block has a pseudo element displaying the word "Foo".

## Screenshots or screencast

Before After
https://github.com/user-attachments/assets/7c1782b4-c5ed-4c95-9456-b21b94d64511 https://github.com/user-attachments/assets/b3b7f3dc-05bc-4cfd-b3d2-9c35e6d736ed
Before After
https://github.com/user-attachments/assets/50c71d68-4649-4148-b965-046c33c8d9a5 https://github.com/user-attachments/assets/0f2d3e36-7c91-4625-a20e-fafd49b3d672

Trac ticket: https://core.trac.wordpress.org/ticket/61769

@ramonopoly commented on PR #7097:


6 weeks ago
#2

I tested along the lines of https://github.com/WordPress/gutenberg/pull/63980 also LGTM

Thanks for reviewing so quickly, folks!

#3 @hellofromTonya
5 weeks ago

  • Owner set to hellofromTonya
  • Status changed from new to reviewing
  • Version changed from trunk to 6.6

Changing the version to 6.6.0 as it appears [56812] introduced the bug.

Self-assigning for review and commit.

#4 @hellofromTonya
4 weeks ago

  • Keywords has-testing-info added

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/7097

Environment

  • OS: macOS
  • Web Server: Core's Docker instance
  • PHP: 7.4.29
  • WordPress: 6.7-alpha-58576-src
  • Browser: Firefox 129.0.1
  • Theme: Twenty Twenty-Four
  • Active Plugins: None

Actual Results

When reproducing a bug/defect:

  • ❌ 'Foo' is not added to the start of each header.
  • ❌ the generated CSS is not expected:
:root :where(.wp-block-heading::before ){content: 'Foo'}

Also noting, the following empty CSS exists, which is not expected:

:root :where(.wp-block-heading){}

When testing the bugfix patch:

  • ✅ 'Foo' is added to the start of each header.
  • ✅ The generated CSS is as expected.
:root :where(.wp-block-heading)::before{content: 'Foo'}
  • ✅ The empty CSS no longer exists.

Observations

Using the provided testing instructions, I'm able to reproduce the reported issue and the patch resolves it.

#5 @hellofromTonya
4 weeks ago

  • Keywords commit added

Patch: https://github.com/WordPress/wordpress-develop/pull/7097

  • ✅ Tests well for me (see test report).
  • ✅ There are multiple test reports and approvals in the PR and the original Gutenberg PR.
  • ✅ All PHP changes from the original Gutenberg PR are included.

LGTM for commit 👍

#6 @hellofromTonya
4 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 58896:

Editor: Fix block custom CSS pseudo element selectors in global styles.

Fixes a regression introduced in [58241] where selectors with pseudo elements are wrapped within :where() causing malformed CSS and the CSS rule(s) not being applied.

When processing custom CSS for blocks, this changeset:

  • Strips the pseudo-elements from the original nested selector, performs the required wrapping in :root :where, then re-appends the pseudo-element selector with its leading combinators if present.
  • Removes empty CSS rules.

It includes the PHP changes.

Reference:

Follow-up to [58241], [56812], [55216].

Props aaronrobertshaw, wongjn, harlet7, dballari, ramonopoly, andrewserong, aristath, hellofromTonya.
Fixes #61769.

#8 @hellofromTonya
4 weeks ago

  • Keywords fixed-major dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 2nd committer sign-off to backport [58896] to the 6.6 branch.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


3 weeks ago

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


2 weeks ago

#11 @hellofromTonya
10 days ago

  • Description modified (diff)

Pinging committers involved in this change for a 2nd committer sign-off to backport it to the 6.6. branch for 6.6.2 RC1 on Sep 4th.

@aaronrobertshaw @andrewserong @talldanwp

This ticket was mentioned in Slack in #core-editor by hellofromtonya. View the logs.


10 days ago

#13 @andrewserong
10 days ago

  • Keywords dev-reviewed added; dev-feedback removed

I've re-tested https://github.com/WordPress/wordpress-develop/pull/7097 applied on the 6.6 branch and it's all working correctly. Adding the dev-reviewed keyword, marking this as ready for backporting to the 6.6 branch.

This ticket was mentioned in Slack in #core-editor by andrewserong. View the logs.


10 days ago

#15 @hellofromTonya
9 days ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 58987:

Editor: Fix block custom CSS pseudo element selectors in global styles.

Fixes a regression introduced in [58241] where selectors with pseudo elements are wrapped within :where() causing malformed CSS and the CSS rule(s) not being applied.

When processing custom CSS for blocks, this changeset:

  • Strips the pseudo-elements from the original nested selector, performs the required wrapping in :root :where, then re-appends the pseudo-element selector with its leading combinators if present.
  • Removes empty CSS rules.

It includes the PHP changes.

Reference:

Follow-up to [58241], [56812], [55216].

Reviewed by andrewserong.
Merges [58896] to the 6.6 branch.

Props aaronrobertshaw, wongjn, harlet7, dballari, ramonopoly, andrewserong, aristath, hellofromTonya.
Fixes #61769.

Note: See TracTickets for help on using tickets.