Skip to content

Commit

Permalink
Optimize preload paths only for core/edit-post page
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed May 1, 2022
1 parent 6fab3c4 commit c8bc405
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/compat/wordpress-6.0/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
/**
* Optimizes the preload paths registered in Core (`edit-form-blocks.php`).
*
* @param array $preload_paths Preload paths to be filtered.
* @param array $preload_paths Preload paths to be filtered.
* @param WP_Block_Editor_Context $block_editor_context The current block editor context.
*
* @return array
*/
function gutenberg_optimize_preload_paths( $preload_paths ) {
function gutenberg_optimize_preload_paths( $preload_paths, $block_editor_context ) {
// optimize only the post editor page, not site or widgets.
if ( 'core/edit-post' !== $block_editor_context->name ) {
return $preload_paths;
}

// remove preload of the `/` route.
$root_index = array_search( '/', $preload_paths, true );
if ( false !== $root_index ) {
Expand Down Expand Up @@ -48,7 +55,7 @@ function gutenberg_optimize_preload_paths( $preload_paths ) {

return $preload_paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths' );
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths', 10, 2 );

/**
* Disables loading remote block patterns from REST while initializing the editor.
Expand Down

0 comments on commit c8bc405

Please sign in to comment.