Skip to content

Commit

Permalink
Site Editor: preload settings requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 29, 2024
1 parent aa7bb5a commit 1f1cb92
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Preload necessary resources for the editors.
*
* @param array $paths REST API paths to preload.
* @param WP_Block_Editor_Context $context Current block editor context
*
* @return array Filtered preload paths.
*/
function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
if ( 'core/edit-site' === $context->name ) {
$paths[] = '/wp/v2/settings';
$paths[] = array( '/wp/v2/settings', 'OPTIONS' );
// Append a pseudo context value to allow preloading twice. `canUser`
// uses the same path. Ideally the raw result is cached and used by both
// `canUser` and `loadSiteEntity`.
$paths[] = array( '/wp/v2/settings?context=schema', 'OPTIONS' );
}
return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_8', 10, 2 );
3 changes: 3 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.7/compat.php';
require __DIR__ . '/compat/wordpress-6.7/post-formats.php';

// WordPress 6.8 compat.
require __DIR__ . '/compat/wordpress-6.8/preload.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
require __DIR__ . '/experimental/blocks.php';
Expand Down
5 changes: 4 additions & 1 deletion packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ async function loadSiteEntity() {
};

const site = await apiFetch( {
path: entity.baseURL,
// Append a pseudo context value to allow preloading twice. `canUser`
// uses the same path. Ideally the raw result is cached and used by both
// `canUser` and `loadSiteEntity`.
path: entity.baseURL + '?context=schema',
method: 'OPTIONS',
} );

Expand Down

0 comments on commit 1f1cb92

Please sign in to comment.