Make WordPress Core


Ignore:
Timestamp:
10/12/2023 04:39:27 PM (18 months ago)
Author:
Bernhard Reiter
Message:

Patterns: Don't inject theme attribute on frontend.

Having the patterns registry inject the theme attribute into all Template Part blocks inside every pattern was found to negatively impact performance. It turns out that it's only required for the editor (i.e. in the REST API) but not on the frontend; there, it's instead possible to fall back to the currently active theme.

The latter change was made to the Pattern and Template Part blocks in https://github.com/WordPress/gutenberg/pull/55217, which was sync'ed to Core in [56849]. Consequently, this changeset removes theme attribute insertion from the frontend.

Props flixos90, gziolo, dmsnell, hellofromtonya.
Fixes #59583.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php

    r56818 r56896  
    318318
    319319    /**
    320      * Should insert a theme attribute into Template Part blocks in registered patterns.
    321      *
    322      * @ticket 59583
    323      *
    324      * @covers WP_Block_Patterns_Registry::register
    325      * @covers WP_Block_Patterns_Registry::get_all_registered
    326      */
    327     public function test_get_all_registered_includes_theme_attribute() {
    328         $test_pattern = array(
    329             'title'   => 'Test Pattern',
    330             'content' => '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->',
    331         );
    332         $this->registry->register( 'test/pattern', $test_pattern );
    333 
    334         $expected = sprintf(
    335             '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->',
    336             get_stylesheet()
    337         );
    338         $patterns = $this->registry->get_all_registered();
    339         $this->assertSame( $expected, $patterns[0]['content'] );
    340     }
    341 
    342     /**
    343320     * Should insert hooked blocks into registered patterns.
    344321     *
     
    393370
    394371    /**
    395      * Should insert a theme attribute into Template Part blocks in registered patterns.
    396      *
    397      * @ticket 59583
    398      *
    399      * @covers WP_Block_Patterns_Registry::register
    400      * @covers WP_Block_Patterns_Registry::get_registered
    401      */
    402     public function test_get_registered_includes_theme_attribute() {
    403         $test_pattern = array(
    404             'title'   => 'Test Pattern',
    405             'content' => '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->',
    406         );
    407         $this->registry->register( 'test/pattern', $test_pattern );
    408 
    409         $expected = sprintf(
    410             '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->',
    411             get_stylesheet()
    412         );
    413         $pattern  = $this->registry->get_registered( 'test/pattern' );
    414         $this->assertSame( $expected, $pattern['content'] );
    415     }
    416 
    417     /**
    418372     * Should insert hooked blocks into registered patterns.
    419373     *
Note: See TracChangeset for help on using the changeset viewer.