From 15d8e0a5eae81a95638b1c3de2d193ed68f03cbe Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 11 May 2023 13:46:39 +0100 Subject: [PATCH] Preload request for fallback --- .../wordpress-6.3/navigation-block-preloading.php | 11 +++++++++++ packages/core-data/src/resolvers.js | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.3/navigation-block-preloading.php b/lib/compat/wordpress-6.3/navigation-block-preloading.php index 82fe81b236a590..c708d0e8585ff4 100644 --- a/lib/compat/wordpress-6.3/navigation-block-preloading.php +++ b/lib/compat/wordpress-6.3/navigation-block-preloading.php @@ -58,6 +58,17 @@ function gutenberg_preload_navigation_posts( $preload_paths, $context ) { 'GET', ); + // Preload the request for a fallback navigation menu. + $preload_paths[] = array( + add_query_arg( + array( + '_embed' => 1, + ), + 'wp-block-editor/v1/navigation-fallback' + ), + 'GET', + ); + return $preload_paths; } add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_preload_navigation_posts', 10, 2 ); diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 6437b759976901..cc89bb534eee5f 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -576,7 +576,10 @@ export const getNavigationFallbackId = async ( { dispatch } ) => { const fallback = await apiFetch( { path: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', { - _embed: true, + // _embed is intentionally set as `1` (as opposed to `true`) + // to ensure preloading of this request works correctly. + // see https://github.com/WordPress/gutenberg/pull/48683/#issuecomment-1543726404. + _embed: 1, } ), } );