Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDefaultTemplateId: ensure entity config is loaded #66650

Merged
merged 5 commits into from
Nov 1, 2024
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
5 changes: 1 addition & 4 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
}
}

// Core already preloads both of these for `core/edit-post`.
// To do: investigate why adding this preload path breaks the site
// editor in Safari ("template not found"). Perhaps a race condition?
// $paths[] = '/wp/v2/settings';
$paths[] = '/wp/v2/settings';
$paths[] = array( '/wp/v2/settings', 'OPTIONS' );
$paths[] = '/?_fields=' . implode(
',',
Expand Down
9 changes: 5 additions & 4 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,13 @@ export const getNavigationFallbackId =

export const getDefaultTemplateId =
( query ) =>
async ( { dispatch, registry } ) => {
const response = await apiFetch( {
async ( { dispatch, registry, resolveSelect } ) => {
const template = await apiFetch( {
path: addQueryArgs( '/wp/v2/templates/lookup', query ),
parse: false,
} );
const template = await response.json();
// Wait for the the entities config to be loaded, otherwise receiving
// the template as an entity will not work.
await resolveSelect.getEntitiesConfig( 'postType' );
Copy link
Member

Choose a reason for hiding this comment

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

Let's add an inline comment here. Otherwise, the resolution seems out of place and can be accidentally removed.

// Endpoint may return an empty object if no template is found.
if ( template?.id ) {
registry.batch( () => {
Expand Down
Loading