Make WordPress Core


Ignore:
Timestamp:
07/18/2024 11:58:22 AM (5 months ago)
Author:
hellofromTonya
Message:

Block Themes: Avoid specificity bump for top-level element-only selectors.

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

Ref: PHP changes from https://github.com/WordPress/gutenberg/pull/63403.

Reviewed by hellofromTonya.
Merges [58749] to the 6.6 branch.

Props aaronrobertshaw, andrewserong, noisysocks, annubis, butterflymedia, clarktbt, hellofromTonya, jorbin, joedolson, swissspidy, courane01, raquelandefeld, talldanwp, markhowellsmead, youknowriad, poena, cbirdsong.
Fixes #61630, #61660.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/src/wp-includes/class-wp-theme-json.php

    r58696 r58751  
    28802880        }
    28812881
     2882        /*
     2883         * Top-level element styles using element-only specificity selectors should
     2884         * not get wrapped in `:root :where()` to maintain backwards compatibility.
     2885         *
     2886         * Pseudo classes, e.g. :hover, :focus etc., are a class-level selector so
     2887         * still need to be wrapped in `:root :where` to cap specificity for nested
     2888         * variations etc. Pseudo selectors won't match the ELEMENTS selector exactly.
     2889         */
     2890        $element_only_selector = $current_element &&
     2891            isset( static::ELEMENTS[ $current_element ] ) &&
     2892            // buttons, captions etc. still need `:root :where()` as they are class based selectors.
     2893            ! isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $current_element ] ) &&
     2894            static::ELEMENTS[ $current_element ] === $selector;
     2895
    28822896        // 2. Generate and append the rules that use the general selector.
    2883         $block_rules .= static::to_ruleset( ":root :where($selector)", $declarations );
     2897        $general_selector = $element_only_selector ? $selector : ":root :where($selector)";
     2898        $block_rules     .= static::to_ruleset( $general_selector, $declarations );
    28842899
    28852900        // 3. Generate and append the rules that use the duotone selector.
Note: See TracChangeset for help on using the changeset viewer.