Make WordPress Core

Changeset 59881


Ignore:
Timestamp:
02/27/2025 10:12:10 PM (18 months ago)
Author:
flixos90
Message:

General: Allow speculative loading opt-out CSS classes to be applied on parent element, e.g. at the block level.

Follow-up to [59837].

Props flixos90, westonruter.
Fixes #63032.
See #62503.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/speculative-loading.php

    r59837 r59881  
    191191                        ),
    192192                ),
    193                 // Also exclude links that are explicitly marked to opt out.
    194                 array(
    195                         'not' => array(
    196                                 'selector_matches' => ".no-{$mode}",
    197                         ),
    198                 ),
    199         );
    200 
    201         // If using 'prerender', also exclude links that opt-out of 'prefetch' because it's part of 'prerender'.
     193                // Also exclude links that are explicitly marked to opt out, either directly or via a parent element.
     194                array(
     195                        'not' => array(
     196                                'selector_matches' => ".no-{$mode}, .no-{$mode} a",
     197                        ),
     198                ),
     199        );
     200
     201        // If using 'prerender', also exclude links that opt out of 'prefetch' because it's part of 'prerender'.
    202202        if ( 'prerender' === $mode ) {
    203203                $main_rule_conditions[] = array(
    204204                        'not' => array(
    205                                 'selector_matches' => '.no-prefetch',
     205                                'selector_matches' => '.no-prefetch, .no-prefetch a',
    206206                        ),
    207207                );
  • trunk/tests/phpunit/tests/speculative-loading/wpGetSpeculationRules.php

    r59837 r59881  
    140140                $this->assertArrayHasKey( 'not', $rules['prefetch'][0]['where']['and'][3] );
    141141                $this->assertArrayHasKey( 'selector_matches', $rules['prefetch'][0]['where']['and'][3]['not'] );
    142                 $this->assertSame( '.no-prefetch', $rules['prefetch'][0]['where']['and'][3]['not']['selector_matches'] );
     142                $this->assertSame( '.no-prefetch, .no-prefetch a', $rules['prefetch'][0]['where']['and'][3]['not']['selector_matches'] );
    143143        }
    144144
     
    165165                $this->assertArrayHasKey( 'not', $rules['prerender'][0]['where']['and'][3] );
    166166                $this->assertArrayHasKey( 'selector_matches', $rules['prerender'][0]['where']['and'][3]['not'] );
    167                 $this->assertSame( '.no-prerender', $rules['prerender'][0]['where']['and'][3]['not']['selector_matches'] );
     167                $this->assertSame( '.no-prerender, .no-prerender a', $rules['prerender'][0]['where']['and'][3]['not']['selector_matches'] );
    168168                $this->assertArrayHasKey( 'not', $rules['prerender'][0]['where']['and'][4] );
    169169                $this->assertArrayHasKey( 'selector_matches', $rules['prerender'][0]['where']['and'][4]['not'] );
    170                 $this->assertSame( '.no-prefetch', $rules['prerender'][0]['where']['and'][4]['not']['selector_matches'] );
     170                $this->assertSame( '.no-prefetch, .no-prefetch a', $rules['prerender'][0]['where']['and'][4]['not']['selector_matches'] );
    171171        }
    172172
Note: See TracChangeset for help on using the changeset viewer.