From 83ebfd727636aef129e04adfffe9365c81d80690 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:38:05 +0200 Subject: [PATCH 1/6] Site Editor: preload settings requests --- lib/compat/wordpress-6.8/preload.php | 22 ++++++++++++++++++++++ lib/load.php | 3 +++ packages/core-data/src/entities.js | 5 ++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/compat/wordpress-6.8/preload.php diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php new file mode 100644 index 0000000000000..612f244b83a9f --- /dev/null +++ b/lib/compat/wordpress-6.8/preload.php @@ -0,0 +1,22 @@ +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 ); \ No newline at end of file diff --git a/lib/load.php b/lib/load.php index 2c8a0fd0347c9..0540d4cd9efac 100644 --- a/lib/load.php +++ b/lib/load.php @@ -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'; diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index f73239e9afbbe..e0253e505acf3 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -411,7 +411,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', } ); From 3f4a31238971c7351d7178caec59b0a2164b0978 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:49:35 +0200 Subject: [PATCH 2/6] add comments --- packages/core-data/src/entities.js | 1 + .../sync-state-with-url/use-init-edited-entity-from-url.js | 1 + .../editor/src/components/provider/use-block-editor-settings.js | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index e0253e505acf3..e1148b5f51fd4 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -414,6 +414,7 @@ async function loadSiteEntity() { // 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`. + // Please check the preloaded paths whenever this is changed. path: entity.baseURL + '?context=schema', method: 'OPTIONS', } ); diff --git a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js index 35eeb5963fb54..e6555d30fcaf1 100644 --- a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +++ b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js @@ -39,6 +39,7 @@ function useResolveEditedEntityAndContext( { postId, postType } ) { frontPageTemplateId, } = useSelect( ( select ) => { const { getEntityRecord, getEntityRecords } = select( coreDataStore ); + // Please check the preloaded paths whenever this is changed. const siteData = getEntityRecord( 'root', 'site' ); const base = getEntityRecord( 'root', '__unstableBase' ); const templates = getEntityRecords( 'postType', TEMPLATE_POST_TYPE, { diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 170ec96c10728..df0a2d66bdc99 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -139,6 +139,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { const { getBlockTypes } = select( blocksStore ); const { getBlocksByName, getBlockAttributes } = select( blockEditorStore ); + // Please check the preloaded paths whenever this is changed. const siteSettings = canUser( 'read', { kind: 'root', name: 'site', From 29da87f7c6c39961fa335be616ea7a0c4d5b136b Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:59:49 +0100 Subject: [PATCH 3/6] one problem at a time --- lib/compat/wordpress-6.8/preload.php | 7 ++----- packages/core-data/src/entities.js | 6 +----- .../sync-state-with-url/use-init-edited-entity-from-url.js | 1 - .../src/components/provider/use-block-editor-settings.js | 1 - 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php index 612f244b83a9f..084c2d5d49ce9 100644 --- a/lib/compat/wordpress-6.8/preload.php +++ b/lib/compat/wordpress-6.8/preload.php @@ -10,13 +10,10 @@ */ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) { if ( 'core/edit-site' === $context->name ) { + // Core already preloads both of these for `core/edit-post`. $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 ); \ No newline at end of file +add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_8', 10, 2 ); diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index e1148b5f51fd4..f73239e9afbbe 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -411,11 +411,7 @@ async function loadSiteEntity() { }; const site = await apiFetch( { - // 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`. - // Please check the preloaded paths whenever this is changed. - path: entity.baseURL + '?context=schema', + path: entity.baseURL, method: 'OPTIONS', } ); diff --git a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js index e6555d30fcaf1..35eeb5963fb54 100644 --- a/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +++ b/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js @@ -39,7 +39,6 @@ function useResolveEditedEntityAndContext( { postId, postType } ) { frontPageTemplateId, } = useSelect( ( select ) => { const { getEntityRecord, getEntityRecords } = select( coreDataStore ); - // Please check the preloaded paths whenever this is changed. const siteData = getEntityRecord( 'root', 'site' ); const base = getEntityRecord( 'root', '__unstableBase' ); const templates = getEntityRecords( 'postType', TEMPLATE_POST_TYPE, { diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index df0a2d66bdc99..170ec96c10728 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -139,7 +139,6 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { const { getBlockTypes } = select( blocksStore ); const { getBlocksByName, getBlockAttributes } = select( blockEditorStore ); - // Please check the preloaded paths whenever this is changed. const siteSettings = canUser( 'read', { kind: 'root', name: 'site', From 02b5a69dd70509da39e4ec366c3dc45879cc9f4c Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:10:22 +0100 Subject: [PATCH 4/6] Preload also __unstableBase --- lib/compat/wordpress-6.8/preload.php | 15 +++++++++++++++ packages/core-data/src/entities.js | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php index 084c2d5d49ce9..f10e311713145 100644 --- a/lib/compat/wordpress-6.8/preload.php +++ b/lib/compat/wordpress-6.8/preload.php @@ -13,6 +13,21 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) { // Core already preloads both of these for `core/edit-post`. $paths[] = '/wp/v2/settings'; $paths[] = array( '/wp/v2/settings', 'OPTIONS' ); + $paths[] = '/?_fields=' . implode( + ',', + // @see packages/core-data/src/entities.js + [ + 'description', + 'gmt_offset', + 'home', + 'name', + 'site_icon', + 'site_icon_url', + 'site_logo', + 'timezone_string', + 'url', + ] + ); } return $paths; } diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index f73239e9afbbe..3c10676750a2a 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -20,6 +20,8 @@ export const rootEntitiesConfig = [ name: '__unstableBase', baseURL: '/', baseURLParams: { + // Please also change the preload path when changing this. + // @see lib/compat/wordpress-6.8/preload.php _fields: [ 'description', 'gmt_offset', From d69264594c357871ed5c20947409ed3cda802a52 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:15:32 +0100 Subject: [PATCH 5/6] Add backport --- backport-changelog/6.8/7687.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/6.8/7687.md diff --git a/backport-changelog/6.8/7687.md b/backport-changelog/6.8/7687.md new file mode 100644 index 0000000000000..f1505645df20c --- /dev/null +++ b/backport-changelog/6.8/7687.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/7687 + +* https://github.com/WordPress/gutenberg/pull/66488 From e6ace622b6f5a551f0c945df1976e5feaa2a202d Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:20:26 +0100 Subject: [PATCH 6/6] php lint --- lib/compat/wordpress-6.8/preload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php index f10e311713145..5ba613e22033d 100644 --- a/lib/compat/wordpress-6.8/preload.php +++ b/lib/compat/wordpress-6.8/preload.php @@ -16,7 +16,7 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) { $paths[] = '/?_fields=' . implode( ',', // @see packages/core-data/src/entities.js - [ + array( 'description', 'gmt_offset', 'home', @@ -26,7 +26,7 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) { 'site_logo', 'timezone_string', 'url', - ] + ) ); } return $paths;