From c5f96c8c1e7cf197189e22e97036f4e6eff23d4a Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Fri, 9 Aug 2024 15:40:19 +0000 Subject: [PATCH] Theme JSON: Ensure root selector (body) is not wrapped in :root :where(). Pre-WordPress 6.6, the `body` selector was used for styles associated with the body. In 6.6, this was mistakenly changed to `:root :where(body)`, an increase in specificity, causing some issues for themes. This change reverts the specificity increase, styles again use the `body` selector. Syncs PHP changes from https://github.com/WordPress/gutenberg/pull/63726. Reviewed by hellofromTonya. Merges [58856] and [58861] to the 6.6 branch. Props talldanwp, andrewserong, aaronrobertshaw, mukesh27, hellofromTonya. Fixes #61704. Built from https://develop.svn.wordpress.org/branches/6.6@58874 git-svn-id: http://core.svn.wordpress.org/branches/6.6@58270 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 9 +++++++-- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 458a23d3e1..bcbf16b762 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -2880,6 +2880,9 @@ class WP_Theme_JSON { } /* + * Root selector (body) styles should not be wrapped in `:root where()` to keep + * specificity at (0,0,1) and maintain backwards compatibility. + * * Top-level element styles using element-only specificity selectors should * not get wrapped in `:root :where()` to maintain backwards compatibility. * @@ -2887,11 +2890,13 @@ class WP_Theme_JSON { * 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 && + $element_only_selector = $is_root_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; + static::ELEMENTS[ $current_element ] === $selector + ); // 2. Generate and append the rules that use the general selector. $general_selector = $element_only_selector ? $selector : ":root :where($selector)"; diff --git a/wp-includes/version.php b/wp-includes/version.php index c003f8e8ad..816bef3f55 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6.2-alpha-58869'; +$wp_version = '6.6.2-alpha-58874'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.