Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.0/11948.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/11948

* https://github.com/WordPress/gutenberg/pull/78565
28 changes: 28 additions & 0 deletions lib/compat/wordpress-7.0/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,31 @@ function gutenberg_block_editor_preload_paths_root_fields( $paths ) {
return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' );

/**
* Preload bound single-resource GETs the post editor would otherwise
* fetch post-mount.
*
* @param array $paths REST API paths.
* @param WP_Block_Editor_Context $context Block editor context.
* @return array
*/
function gutenberg_block_editor_preload_paths_post_editor_bound_gets( $paths, $context ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in the WP 7.1 directory.

if ( 'core/edit-post' !== $context->name || ! isset( $context->post ) ) {
return $paths;
}
$paths[] = '/wp/v2/templates/lookup?slug=front-page';
$paths[] = '/wp/v2/taxonomies?context=edit';
$paths[] = array( '/wp/v2/posts', 'OPTIONS' );

$author_id = (int) get_post_field( 'post_author', $context->post->ID );
if ( $author_id ) {
$paths[] = sprintf(
'/wp/v2/users/%d?context=view&_fields=id,name',
$author_id
);
}
Comment on lines +74 to +83

@Mamaduka Mamaduka Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the options request should be made for the current post type, and we should use rest_get_route_for_post_type_items.

We should also check if the post type supports the author. IIRC, this request is made by the Post Author component, which isn't rendered when not supported.

Screenshot from Patterns post editor

Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the follow-up - #79359.


return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_post_editor_bound_gets', 10, 2 );
6 changes: 5 additions & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,10 +1032,14 @@ export const getDefaultTemplateId =
};

getDefaultTemplateId.shouldInvalidate = ( action ) => {
// Only invalidate on real saves; `persistedEdits` is absent on
// initial fetches so the kickoff's own site read doesn't wipe
// the just-resolved template id.
return (
action.type === 'RECEIVE_ITEMS' &&
action.kind === 'root' &&
action.name === 'site'
action.name === 'site' &&
!! action.persistedEdits
);
};

Expand Down
15 changes: 15 additions & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ async function preloadResolutions( postType, postId ) {
core.getEntitiesConfig( 'postType' ),
core.getEntitiesConfig( 'taxonomy' ),
core.getEntitiesConfig( 'root' ),
core.getEntityRecords( 'root', 'taxonomy' ),
core.getCurrentTheme(),
// Forward-resolver alias of `getCurrentTheme` with its own
// resolution metadata, so it needs a separate kick.
Expand Down Expand Up @@ -236,6 +237,11 @@ async function preloadResolutions( postType, postId ) {
postId
),
core.getAutosaves( postType, postId ),
core.getDefaultTemplateId( { slug: 'front-page' } ),
core.canUser( 'create', {
kind: 'postType',
name: postType,
} ),
]
: [] ),
] );
Expand Down Expand Up @@ -268,6 +274,15 @@ async function preloadResolutions( postType, postId ) {
slug += '-' + post.slug;
}
tasks.push( core.getDefaultTemplateId( { slug } ) );

if ( post.author ) {
tasks.push(
core.getUser( post.author, {
context: 'view',
_fields: 'id,name',
} )
);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
await page
.getByRole( 'button', { name: 'Meta Boxes' } )
.click( { position: { x: 0, y: 0 } } );
await page.locator( 'role=button[name="Visual"i]' ).click();
// Switch tinymce to Text mode, first waiting for it to initialize
// because otherwise it will flip back to Visual mode once initialized.
await page.locator( '#test_tinymce_id_ifr' ).waitFor();
Expand All @@ -45,6 +46,6 @@
await page.reload();

// Expect the typed text in the tinymce Text mode textarea.
await expect( metaBoxField ).toHaveValue( 'Typing in a metabox' );

Check failure on line 49 in test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › specs/editor/plugins/wp-editor-meta-box.spec.js:19:2 › WP Editor Meta Boxes › Should save the changes

1) [chromium] › specs/editor/plugins/wp-editor-meta-box.spec.js:19:2 › WP Editor Meta Boxes › Should save the changes Error: expect(locator).toHaveValue(expected) failed Locator: locator('#test_tinymce_id') Expected: "Typing in a metabox" Received: "Typing in a metabox<span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\"></span>" Timeout: 5000ms Call log: - Expect "toHaveValue" with timeout 5000ms - waiting for locator('#test_tinymce_id') 8 × locator resolved to <textarea rows="10" cols="40" autocomplete="off" name="test_tinymce" id="test_tinymce_id" class="wp-editor-area">Typing in a metabox<span data-mce-type="bookmark"…</textarea> - unexpected value "Typing in a metabox<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>" 47 | 48 | // Expect the typed text in the tinymce Text mode textarea. > 49 | await expect( metaBoxField ).toHaveValue( 'Typing in a metabox' ); | ^ 50 | } ); 51 | } ); 52 | at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js:49:32
} );
} );
4 changes: 0 additions & 4 deletions test/e2e/specs/preload/post-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ test.describe( 'Preload', () => {
expect( Array.from( new Set( requests ) ).sort() ).toEqual(
[
`GET /wp/v2/comments?context=edit&post=${ postId }&type=note&status=all&per_page=100`,
'GET /wp/v2/taxonomies?context=edit',
'GET /wp/v2/templates/lookup?slug=front-page',
'GET /wp/v2/users/1?context=view&_fields=id%2Cname',
'GET /wp/v2/wp_pattern_category?context=view&per_page=100&_fields=id%2Cname%2Cdescription%2Cslug',
'OPTIONS /wp/v2/posts',
`POST /wp/v2/posts/${ postId }`,
'POST /wp-sync/v1/updates',
'POST /wp/v2/users/me',
Expand Down
Loading