Make WordPress Core


Ignore:
Timestamp:
10/12/2023 04:39:27 PM (3 years 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/src/wp-includes/block-template-utils.php

    r56819 r56896  
    550550        }
    551551
    552         $before_block_visitor = '_inject_theme_attribute_in_template_part_block';
     552        $before_block_visitor = ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ? '_inject_theme_attribute_in_template_part_block' : null;
    553553        $after_block_visitor  = null;
    554554        $hooked_blocks        = get_hooked_blocks();
    … …  
    557557                $after_block_visitor  = make_after_block_visitor( $hooked_blocks, $template );
    558558        }
    559         $blocks            = parse_blocks( $template_content );
    560         $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
     559        if ( null !== $before_block_visitor || null !== $after_block_visitor ) {
     560                $blocks           = parse_blocks( $template_content );
     561                $template_content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
     562        }
     563        $template->content = $template_content;
    561564
    562565        return $template;
Note: See TracChangeset for help on using the changeset viewer.