Make WordPress Core


Ignore:
Timestamp:
08/06/2024 08:24:14 AM (2 years ago)
Author:
talldanwp
Message:

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.

Props talldanwp, andrewserong, aaronrobertshaw, mukesh27, hellofromtonya.
Fixes #61704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r58834 r58856  
    27392739         *              Updated general global styles specificity to 0-1-0.
    27402740         *              Fixed custom CSS output in block style variations.
     2741         * @since 6.6.1 Avoid applying `:root :where()` wrapper to top-level element-only selectors.
     2742         * @since 6.6.2 Avoid applying `:root :where()` wrapper to root selectors.
    27412743         *
    27422744         * @param array $block_metadata Metadata about the block to get styles for.
     
    28932895
    28942896                /*
     2897                 * Root selector (body) styles should not be wrapped in `:root where()` to keep
     2898                 * specificity at (0,0,1) and maintain backwards compatibility.
     2899                 *
    28952900                 * Top-level element styles using element-only specificity selectors should
    28962901                 * not get wrapped in `:root :where()` to maintain backwards compatibility.
     
    29002905                 * variations etc. Pseudo selectors won't match the ELEMENTS selector exactly.
    29012906                 */
    2902                 $element_only_selector = $current_element &&
     2907                $element_only_selector = $is_root_selector || (
     2908                        $current_element &&
    29032909                        isset( static::ELEMENTS[ $current_element ] ) &&
    29042910                        // buttons, captions etc. still need `:root :where()` as they are class based selectors.
    29052911                        ! isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $current_element ] ) &&
    2906                         static::ELEMENTS[ $current_element ] === $selector;
     2912                        static::ELEMENTS[ $current_element ] === $selector
     2913                );
    29072914
    29082915                // 2. Generate and append the rules that use the general selector.
Note: See TracChangeset for help on using the changeset viewer.