From 1d236b73e2a3282a3f786c427a84f162ee13d9d9 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Thu, 7 May 2026 20:53:32 -0400 Subject: [PATCH 1/6] Editor: Preload initial Site Editor canvas data --- src/wp-admin/site-editor.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 9a8268c3392d7..d2087222d3409 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -237,6 +237,30 @@ static function ( $classes ) { ), ); +$template_parts = get_block_templates( array(), 'wp_template_part' ); +foreach ( $template_parts as $template_part ) { + if ( ! empty( $template_part->id ) ) { + $preload_paths[] = '/wp/v2/template-parts/' . $template_part->id . '?context=edit'; + } +} + +$post_rest_route = rest_get_route_for_post_type_items( 'post' ); +foreach ( array( 10, 3 ) as $per_page ) { + $preload_paths[] = add_query_arg( + array( + 'context' => 'edit', + 'offset' => 0, + 'order' => 'desc', + 'orderby' => 'date', + 'per_page' => $per_page, + 'ignore_sticky' => 'false', + ), + $post_rest_route + ); +} + +$preload_paths[] = '/wp/v2/taxonomies?context=view'; + if ( $block_editor_context->post ) { $route_for_post = rest_get_route_for_post( $block_editor_context->post ); if ( $route_for_post ) { From 8e93af89e336a7f1e5687377b5cb4aeb616bed45 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Fri, 8 May 2026 16:58:49 -0400 Subject: [PATCH 2/6] Editor: Remove redundant template part ID check --- src/wp-admin/site-editor.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index d2087222d3409..2cf3d6fda9d61 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -239,9 +239,7 @@ static function ( $classes ) { $template_parts = get_block_templates( array(), 'wp_template_part' ); foreach ( $template_parts as $template_part ) { - if ( ! empty( $template_part->id ) ) { - $preload_paths[] = '/wp/v2/template-parts/' . $template_part->id . '?context=edit'; - } + $preload_paths[] = '/wp/v2/template-parts/' . $template_part->id . '?context=edit'; } $post_rest_route = rest_get_route_for_post_type_items( 'post' ); From e73ce2fc126400bfe9a54728236ce1185dd4425a Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Fri, 8 May 2026 18:58:13 -0400 Subject: [PATCH 3/6] Editor: Preload route-aware Site Editor canvas data --- src/wp-admin/site-editor.php | 106 ++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 2cf3d6fda9d61..832221378948b 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -237,24 +237,102 @@ static function ( $classes ) { ), ); -$template_parts = get_block_templates( array(), 'wp_template_part' ); -foreach ( $template_parts as $template_part ) { - $preload_paths[] = '/wp/v2/template-parts/' . $template_part->id . '?context=edit'; +$template_slugs = array(); +$front_page = null; +if ( $block_editor_context->post && 'page' === $block_editor_context->post->post_type ) { + $template_slugs[] = empty( $block_editor_context->post->post_name ) ? 'page' : 'page-' . $block_editor_context->post->post_name; + $template_slugs[] = 'page'; +} else { + $template_slugs[] = 'front-page'; + + if ( 'page' === get_option( 'show_on_front' ) ) { + $front_page = get_post( (int) get_option( 'page_on_front' ) ); + if ( $front_page instanceof WP_Post ) { + $template_slugs[] = empty( $front_page->post_name ) ? 'page' : 'page-' . $front_page->post_name; + $template_slugs[] = 'page'; + } + } else { + $template_slugs[] = 'home'; + } + + $template_slugs[] = 'index'; } -$post_rest_route = rest_get_route_for_post_type_items( 'post' ); -foreach ( array( 10, 3 ) as $per_page ) { +$template_slugs = array_values( array_unique( $template_slugs ) ); +$templates = get_block_templates( + array( + 'slug__in' => $template_slugs, + ), + 'wp_template' +); +$priorities = array_flip( $template_slugs ); + +usort( + $templates, + static function ( $template_a, $template_b ) use ( $priorities ) { + return ( $priorities[ $template_a->slug ] ?? 999 ) - ( $priorities[ $template_b->slug ] ?? 999 ); + } +); + +$template_part_ids = array(); +$has_query = false; +$walk_blocks = static function ( $blocks ) use ( &$walk_blocks, &$template_part_ids, &$has_query ) { + foreach ( $blocks as $block ) { + if ( 'core/template-part' === ( $block['blockName'] ?? '' ) && ! empty( $block['attrs']['slug'] ) ) { + $theme = ! empty( $block['attrs']['theme'] ) ? $block['attrs']['theme'] : get_stylesheet(); + $template_part_ids[] = $theme . '//' . $block['attrs']['slug']; + } + + if ( 'core/query' === ( $block['blockName'] ?? '' ) ) { + $has_query = true; + } + + if ( ! empty( $block['innerBlocks'] ) ) { + $walk_blocks( $block['innerBlocks'] ); + } + } +}; + +if ( ! empty( $templates ) && ! empty( $templates[0]->content ) ) { + $blocks = parse_blocks( $templates[0]->content ); + if ( function_exists( 'resolve_pattern_blocks' ) ) { + $blocks = resolve_pattern_blocks( $blocks ); + } + $walk_blocks( $blocks ); +} + +foreach ( array_unique( $template_part_ids ) as $template_part_id ) { + $preload_paths[] = '/wp/v2/template-parts/' . $template_part_id . '?context=edit'; +} + +if ( $front_page instanceof WP_Post ) { + $route_for_front_page = rest_get_route_for_post( $front_page ); + if ( $route_for_front_page ) { + $preload_paths[] = add_query_arg( 'context', 'edit', $route_for_front_page ); + } $preload_paths[] = add_query_arg( - array( - 'context' => 'edit', - 'offset' => 0, - 'order' => 'desc', - 'orderby' => 'date', - 'per_page' => $per_page, - 'ignore_sticky' => 'false', - ), - $post_rest_route + 'slug', + empty( $front_page->post_name ) ? 'page' : 'page-' . $front_page->post_name, + '/wp/v2/templates/lookup' ); + $preload_paths[] = '/wp/v2/types/page?context=edit'; +} + +if ( $has_query ) { + $post_rest_route = rest_get_route_for_post_type_items( 'post' ); + foreach ( array( 10, 3 ) as $per_page ) { + $preload_paths[] = add_query_arg( + array( + 'context' => 'edit', + 'offset' => 0, + 'order' => 'desc', + 'orderby' => 'date', + 'per_page' => $per_page, + 'ignore_sticky' => 'false', + ), + $post_rest_route + ); + } } $preload_paths[] = '/wp/v2/taxonomies?context=view'; From 6c07c37dd20bc9612d899ca5cf7c6ab40c6ff7c7 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Fri, 8 May 2026 19:02:13 -0400 Subject: [PATCH 4/6] Editor: Simplify pattern block resolution --- src/wp-admin/site-editor.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 832221378948b..2190de3ab04dc 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -294,10 +294,7 @@ static function ( $template_a, $template_b ) use ( $priorities ) { }; if ( ! empty( $templates ) && ! empty( $templates[0]->content ) ) { - $blocks = parse_blocks( $templates[0]->content ); - if ( function_exists( 'resolve_pattern_blocks' ) ) { - $blocks = resolve_pattern_blocks( $blocks ); - } + $blocks = resolve_pattern_blocks( parse_blocks( $templates[0]->content ) ); $walk_blocks( $blocks ); } From b4b0b0665690b33b14019c4d5f84ee672a6471f7 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Sun, 10 May 2026 15:31:50 -0400 Subject: [PATCH 5/6] Editor: Address Site Editor preload review feedback --- src/wp-admin/site-editor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 2190de3ab04dc..35fb273fc65a7 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -245,8 +245,9 @@ static function ( $classes ) { } else { $template_slugs[] = 'front-page'; - if ( 'page' === get_option( 'show_on_front' ) ) { - $front_page = get_post( (int) get_option( 'page_on_front' ) ); + $page_on_front = (int) get_option( 'page_on_front' ); + if ( 'page' === get_option( 'show_on_front' ) && $page_on_front > 0 ) { + $front_page = get_post( $page_on_front ); if ( $front_page instanceof WP_Post ) { $template_slugs[] = empty( $front_page->post_name ) ? 'page' : 'page-' . $front_page->post_name; $template_slugs[] = 'page'; @@ -276,7 +277,7 @@ static function ( $template_a, $template_b ) use ( $priorities ) { $template_part_ids = array(); $has_query = false; -$walk_blocks = static function ( $blocks ) use ( &$walk_blocks, &$template_part_ids, &$has_query ) { +$walk_blocks = static function ( array $blocks ) use ( &$walk_blocks, &$template_part_ids, &$has_query ) { foreach ( $blocks as $block ) { if ( 'core/template-part' === ( $block['blockName'] ?? '' ) && ! empty( $block['attrs']['slug'] ) ) { $theme = ! empty( $block['attrs']['theme'] ) ? $block['attrs']['theme'] : get_stylesheet(); From 416c6223049f1cc30b483ae0ad2f8afff202d4fc Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Mon, 11 May 2026 16:01:44 -0400 Subject: [PATCH 6/6] Editor: Preload additional Site Editor metadata --- src/wp-admin/site-editor.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 35fb273fc65a7..dce818edac737 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -318,6 +318,7 @@ static function ( $template_a, $template_b ) use ( $priorities ) { if ( $has_query ) { $post_rest_route = rest_get_route_for_post_type_items( 'post' ); + $preload_paths[] = '/wp/v2/types/post?context=edit'; foreach ( array( 10, 3 ) as $per_page ) { $preload_paths[] = add_query_arg( array( @@ -333,6 +334,17 @@ static function ( $template_a, $template_b ) use ( $priorities ) { } } +$preload_paths[] = add_query_arg( + array( + 'context' => 'edit', + 'per_page' => 100, + '_fields' => 'id,link,menu_order,parent,title,type', + 'orderby' => 'menu_order', + 'order' => 'asc', + ), + rest_get_route_for_post_type_items( 'page' ) +); + $preload_paths[] = '/wp/v2/taxonomies?context=view'; if ( $block_editor_context->post ) {