Make WordPress Core

Opened 8 weeks ago

Closed 7 weeks ago

#65641 closed defect (bug) (maybelater)

Custom CSS: Fix cascade order against block style variations

Reported by: ramonopoly Owned by:
Priority: normal Milestone:
Component: General Version:
Severity: normal Keywords: gutenberg-merge has-patch has-unit-tests
Cc: Focuses:

Description

Trac ticket to backport the Gutenberg PR: https://github.com/WordPress/gutenberg/pull/80340

The Gutenberg PR makes per-block custom CSS reliably win over block style variation (section style) styles, and makes the editor cascade match the front end.

Addresses two of the reports in https://github.com/WordPress/gutenberg/issues/80057 (custom CSS being overridden by block styles, and the editor/front-end mismatch).

The bug:

Style variation styles were overriding custom CSS due to the order in which they are printed.

Both rulesets are wrapped in :root :where() and print at 0-1-0 specificity, so whichever prints later wins.

Change History (4)

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


8 weeks ago
#1

  • Keywords has-patch has-unit-tests added

## Trac ticket

https://core.trac.wordpress.org/ticket/65641

## Description

Backport of WordPress/gutenberg#80340.

Makes per-block custom CSS reliably win over block style variation (section style) styles on the front end. Both rulesets are wrapped in :root :where() and print at 0-1-0 specificity, so whichever prints later wins. That order was accidental: it fell out of enqueue order between the wp-block-custom-css and block-style-variation-styles handles.

### Changes

  • wp-block-custom-css now declares block-style-variation-styles as a dependency, so custom CSS always prints after variation styles.
  • The variation handle is registered on demand if nothing has registered it yet, because a style with an unregistered dependency is never printed at all.

### Testing

  1. Activate a block theme with section styles (e.g., Twenty Twenty-Five).
  2. Add a Group block to a post and apply a section style with a background (e.g., "Style 1").
  3. In the block's Advanced panel, add custom CSS that contests the variation, e.g. background-color: blue;.
  4. Publish and view the post. Confirm the custom CSS value wins on the front end.
  5. Remove the section style and confirm the custom CSS still applies on the front end.

---

This is a PHP-only backport. The editor-side JS changes (cascade ordering of overrides and clientId threading) from the Gutenberg PR are not included — they ship via the Gutenberg plugin.

Props andrewserong, ramonopoly.
Fixes #65641.

@ramonopoly commented on PR #12551:


7 weeks ago
#2

I'm not sure about this one, at least the front end fix. I think I'm going after the symptom and not the virus 😄. I think maybe custom CSS needs special handling not variations. Not sure

#4 @ramonopoly
7 weeks ago

  • Milestone Awaiting Review
  • Resolutionmaybelater
  • Status newclosed

Closing as a mix between won't fix (nothing ostensibly broken in the output) and needs more input/thinking.

https://github.com/WordPress/gutenberg/pull/80340#issuecomment-4998205351

Note: See TracTickets for help on using tickets.