From bd46c6f33354c7610bd69d8ae24517f72634db93 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Tue, 16 Jun 2020 09:49:04 -0700 Subject: [PATCH] FSE: Move initial template fetch to client (#23186) --- lib/edit-site-page.php | 5 ----- lib/template-loader.php | 6 +++--- packages/edit-site/src/components/editor/index.js | 6 +++--- packages/edit-site/src/store/index.js | 7 ++++++- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/edit-site-page.php b/lib/edit-site-page.php index 9704bda44f7f1b..837148666319dc 100644 --- a/lib/edit-site-page.php +++ b/lib/edit-site-page.php @@ -160,12 +160,8 @@ function gutenberg_edit_site_init( $hook ) { } } - $current_template_id = $template_ids['front-page']; - $settings['editSiteInitialState'] = array(); - $settings['editSiteInitialState']['homeTemplateId'] = $current_template_id; - $settings['editSiteInitialState']['templateId'] = $current_template_id; $settings['editSiteInitialState']['templateType'] = 'wp_template'; $settings['editSiteInitialState']['templateIds'] = array_values( $template_ids ); $settings['editSiteInitialState']['templatePartIds'] = array_values( $template_part_ids ); @@ -192,7 +188,6 @@ function gutenberg_edit_site_init( $hook ) { '/wp/v2/taxonomies?per_page=100&context=edit', '/wp/v2/pages?per_page=100&context=edit', '/wp/v2/themes?status=active', - sprintf( '/wp/v2/templates/%s?context=edit', $current_template_id ), array( '/wp/v2/media', 'OPTIONS' ), ); $preload_data = array_reduce( diff --git a/lib/template-loader.php b/lib/template-loader.php index 85bb38aacef578..b50d83765c52f9 100644 --- a/lib/template-loader.php +++ b/lib/template-loader.php @@ -59,7 +59,7 @@ function gutenberg_add_template_loader_filters() { * @param string $template_type A template type. * @return string[] A list of template candidates, in descending order of priority. */ -function get_template_hierachy( $template_type ) { +function get_template_hierarchy( $template_type ) { if ( ! in_array( $template_type, get_template_types(), true ) ) { return array(); } @@ -220,9 +220,9 @@ function gutenberg_find_template_post_and_parts( $template_type, $template_hiera if ( empty( $template_hierarchy ) ) { if ( 'index' === $template_type ) { - $template_hierarchy = get_template_hierachy( 'index' ); + $template_hierarchy = get_template_hierarchy( 'index' ); } else { - $template_hierarchy = array_merge( get_template_hierachy( $template_type ), get_template_hierachy( 'index' ) ); + $template_hierarchy = array_merge( get_template_hierarchy( $template_type ), get_template_hierarchy( 'index' ) ); } } diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index d88c14a2f986a8..2dacc62375ab80 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -144,7 +144,7 @@ function Editor() { } ), [ page.context ] ); - return template ? ( + return ( <> @@ -223,7 +223,7 @@ function Editor() { > - + { template && } } @@ -268,6 +268,6 @@ function Editor() { - ) : null; + ); } export default Editor; diff --git a/packages/edit-site/src/store/index.js b/packages/edit-site/src/store/index.js index b4d5db0ca9c93c..06bcf529febe1e 100644 --- a/packages/edit-site/src/store/index.js +++ b/packages/edit-site/src/store/index.js @@ -14,7 +14,7 @@ import controls from './controls'; import { STORE_KEY } from './constants'; export default function registerEditSiteStore( initialState ) { - return registerStore( STORE_KEY, { + const store = registerStore( STORE_KEY, { reducer, actions, selectors, @@ -22,4 +22,9 @@ export default function registerEditSiteStore( initialState ) { persist: [ 'preferences' ], initialState, } ); + + // We set the initial page here to include the template fetch which will + // resolve the correct homepage template. + store.dispatch( actions.setPage( initialState.page ) ); + return store; }