-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Nav block loading UX by preloading Navigation menu requests (#…
…48683) * Scaffold out preloading * All GET and OPTIONS preloading * Make preload paths more readable via add_query_arg * Add comment to unusual usage * Resolve PHPCS * Fix formatting * Rename away from “permissions” * Limit to Site Editor * Add context to doc block * Preload Browse Mode sidebar Navigation * Remove redundant preload * Use int not string for numeric
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Patches resources loaded by the block editor page | ||
* to include Navigation posts. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Preloads requests needed for Navigation posts | ||
* | ||
* @param array $preload_paths Preload paths to be filtered. | ||
* @param WP_Block_Editor_Context $context The current block editor context. | ||
* @return array | ||
*/ | ||
function gutenberg_preload_navigation_posts( $preload_paths, $context ) { | ||
|
||
// Limit to the Site Editor. | ||
if ( ! empty( $context->name ) && 'core/edit-site' !== $context->name ) { | ||
return $preload_paths; | ||
} | ||
|
||
$navigation_rest_route = rest_get_route_for_post_type_items( | ||
'wp_navigation' | ||
); | ||
|
||
// Preload the OPTIONS request for all Navigation posts request. | ||
$preload_paths[] = array( $navigation_rest_route, 'OPTIONS' ); | ||
|
||
// Preload the GET request for ALL 'published' or 'draft' Navigation posts. | ||
$preload_paths[] = array( | ||
add_query_arg( | ||
array( | ||
'context' => 'edit', | ||
'per_page' => 100, | ||
'_locale' => 'user', | ||
// array indices are required to avoid query being encoded and not matching in cache. | ||
'status[0]' => 'publish', | ||
'status[1]' => 'draft', | ||
), | ||
$navigation_rest_route | ||
), | ||
'GET', | ||
); | ||
|
||
// Preload request for Browse Mode sidebar "Navigation" section. | ||
$preload_paths[] = array( | ||
add_query_arg( | ||
array( | ||
'context' => 'edit', | ||
'per_page' => 1, | ||
'status' => 'publish', | ||
'order' => 'desc', | ||
'orderby' => 'date', | ||
), | ||
$navigation_rest_route | ||
), | ||
'GET', | ||
); | ||
|
||
return $preload_paths; | ||
} | ||
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_preload_navigation_posts', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e7e1b7c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in e7e1b7c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4948062512
📝 Reported issues:
/test/e2e/specs/editor/blocks/image.spec.js
specs/editor/various/autosave.test.js