Skip to content

Block Supports: Fix custom CSS cascade order against block style variations#12551

Closed
ramonjd wants to merge 1 commit into
WordPress:trunkfrom
ramonjd:fix/custom-css-style-variation-order
Closed

Block Supports: Fix custom CSS cascade order against block style variations#12551
ramonjd wants to merge 1 commit into
WordPress:trunkfrom
ramonjd:fix/custom-css-style-variation-order

Conversation

@ramonjd

@ramonjd ramonjd commented Jul 16, 2026

Copy link
Copy Markdown
Member

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.

…ations.

Make per-block custom CSS reliably win over block style variation styles
by declaring `block-style-variation-styles` as a dependency of the
`wp-block-custom-css` style handle. Without this explicit dependency the
order was decided by enqueue order, and custom CSS could lose to variation
styles at equal specificity.

The `block-style-variation-styles` handle is registered on demand if it
doesn't exist yet, because a style with an unregistered dependency is
never printed.

Backport of WordPress/gutenberg#80340.

Props andrewserong, ramonopoly.
Fixes #65641.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ramonopoly.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ramonjd

ramonjd commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

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

@ramonjd

ramonjd commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Closing this as not needed right now.

WordPress/gutenberg#80340 (comment)

@ramonjd ramonjd closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant