Skip to content

Commit

Permalink
Block Themes: Avoid specificity bump for top-level element-only selec…
Browse files Browse the repository at this point in the history
…tors

Prevent issues (e.g. links being underlined) caused by a bump in CSS
specificity for top-level element-only global element styles.

Backports the PHP changes from WordPress/gutenberg#63403.

Fixes #61630.
Fixes #61660.
Props aaronrobertshaw, andrewserong, noisysocks.

Built from https://develop.svn.wordpress.org/trunk@58749


git-svn-id: http://core.svn.wordpress.org/trunk@58151 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
noisysocks committed Jul 18, 2024
1 parent 05c7351 commit a4e3fdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -2888,8 +2888,23 @@ static function ( $pseudo_selector ) use ( $selector ) {
$declarations = static::update_separator_declarations( $declarations );
}

/*
* Top-level element styles using element-only specificity selectors should
* not get wrapped in `:root :where()` to maintain backwards compatibility.
*
* Pseudo classes, e.g. :hover, :focus etc., are a class-level selector so
* still need to be wrapped in `:root :where` to cap specificity for nested
* variations etc. Pseudo selectors won't match the ELEMENTS selector exactly.
*/
$element_only_selector = $current_element &&
isset( static::ELEMENTS[ $current_element ] ) &&
// buttons, captions etc. still need `:root :where()` as they are class based selectors.
! isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $current_element ] ) &&
static::ELEMENTS[ $current_element ] === $selector;

// 2. Generate and append the rules that use the general selector.
$block_rules .= static::to_ruleset( ":root :where($selector)", $declarations );
$general_selector = $element_only_selector ? $selector : ":root :where($selector)";
$block_rules .= static::to_ruleset( $general_selector, $declarations );

// 3. Generate and append the rules that use the duotone selector.
if ( isset( $block_metadata['duotone'] ) && ! empty( $declarations_duotone ) ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-58748';
$wp_version = '6.7-alpha-58749';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit a4e3fdf

Please sign in to comment.