Make WordPress Core


Ignore:
Timestamp:
09/04/2024 02:22:16 PM (2 years ago)
Author:
hellofromTonya
Message:

Editor: Fix block custom CSS pseudo element selectors in global styles.

Fixes a regression introduced in [58241] where selectors with pseudo elements are wrapped within :where() causing malformed CSS and the CSS rule(s) not being applied.

When processing custom CSS for blocks, this changeset:

  • Strips the pseudo-elements from the original nested selector, performs the required wrapping in :root :where, then re-appends the pseudo-element selector with its leading combinators if present.
  • Removes empty CSS rules.

It includes the PHP changes.

Reference:

Follow-up to [58241], [56812], [55216].

Reviewed by andrewserong.
Merges [58896] to the 6.6 branch.

Props aaronrobertshaw, wongjn, harlet7, dballari, ramonopoly, andrewserong, aristath, hellofromTonya.
Fixes #61769.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/tests/phpunit/tests/theme/wpThemeJson.php

    r58986 r58987  
    51545154        /**
    51555155         * @ticket 61165
     5156         * @ticket 61769
    51565157         *
    51575158         * @dataProvider data_process_blocks_custom_css
     
    51815182                return array(
    51825183                        // Simple CSS without any nested selectors.
     5184                        'empty css'                    => array(
     5185                                'input'    => array(
     5186                                        'selector' => '.foo',
     5187                                        'css'      => '',
     5188                                ),
     5189                                'expected' => '',
     5190                        ),
    51835191                        'no nested selectors'          => array(
    51845192                                'input'    => array(
     
    51965204                                'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo.one){color: blue;}:root :where(.foo .two){color: green;}',
    51975205                        ),
     5206                        'no root styles'               => array(
     5207                                'input'    => array(
     5208                                        'selector' => '.foo',
     5209                                        'css'      => '&::before{color: red;}',
     5210                                ),
     5211                                'expected' => ':root :where(.foo)::before{color: red;}',
     5212                        ),
    51985213                        // CSS with pseudo elements.
    51995214                        'with pseudo elements'         => array(
     
    52025217                                        'css'      => 'color: red; margin: auto; &::before{color: blue;} & ::before{color: green;}  &.one::before{color: yellow;} & .two::before{color: purple;}',
    52035218                                ),
    5204                                 'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo::before){color: blue;}:root :where(.foo ::before){color: green;}:root :where(.foo.one::before){color: yellow;}:root :where(.foo .two::before){color: purple;}',
     5219                                'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo)::before{color: blue;}:root :where(.foo) ::before{color: green;}:root :where(.foo.one)::before{color: yellow;}:root :where(.foo .two)::before{color: purple;}',
    52055220                        ),
    52065221                        // CSS with multiple root selectors.
     
    52105225                                        'css'      => 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;} &::before{color: yellow;} & ::before{color: purple;}  &.three::before{color: orange;} & .four::before{color: skyblue;}',
    52115226                                ),
    5212                                 'expected' => ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo::before, .bar::before){color: yellow;}:root :where(.foo ::before, .bar ::before){color: purple;}:root :where(.foo.three::before, .bar.three::before){color: orange;}:root :where(.foo .four::before, .bar .four::before){color: skyblue;}',
     5227                                'expected' => ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo, .bar)::before{color: yellow;}:root :where(.foo, .bar) ::before{color: purple;}:root :where(.foo.three, .bar.three)::before{color: orange;}:root :where(.foo .four, .bar .four)::before{color: skyblue;}',
    52135228                        ),
    52145229                );
Note: See TracChangeset for help on using the changeset viewer.