Skip to content

usePostActions: avoid theme fetch for non template part types #70536

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions packages/editor/src/dataviews/store/private-actions.ts
Original file line number Diff line number Diff line change
@@ -127,9 +127,21 @@
kind: 'postType',
name: postType,
} );
const currentTheme = await registry
.resolveSelect( coreStore )
.getCurrentTheme();

let hasDuplicateTemplatePartAction = false;
if ( postTypeConfig.slug === 'wp_template_part' && canCreate ) {
// Avoid a blocking network request if we can.
hasDuplicateTemplatePartAction = (
await registry.resolveSelect( coreStore ).getCurrentTheme()
)?.is_block_theme;
}

let hasFeaturedImageField = false;
if ( postTypeConfig.supports?.thumbnail ) {
hasFeaturedImageField = (
await registry.resolveSelect( coreStore ).getCurrentTheme()
)?.theme_supports?.[ 'post-thumbnails' ];
}

const actions = [
postTypeConfig.viewable ? viewPost : undefined,
@@ -144,11 +156,7 @@
canCreate &&
duplicatePost
: undefined,
postTypeConfig.slug === 'wp_template_part' &&
canCreate &&
currentTheme?.is_block_theme
? duplicateTemplatePart
: undefined,
hasDuplicateTemplatePartAction ? duplicateTemplatePart : undefined,
canCreate && postTypeConfig.slug === 'wp_block'
? duplicatePattern
: undefined,
@@ -165,9 +173,7 @@
].filter( Boolean );

const fields = [
postTypeConfig.supports?.thumbnail &&
currentTheme?.theme_supports?.[ 'post-thumbnails' ] &&
featuredImageField,
hasFeaturedImageField ? featuredImageField : undefined,
postTypeConfig.supports?.author && authorField,
statusField,
dateField,
@@ -191,7 +197,7 @@
} else {
_titleField = titleField;
}
fields.push( _titleField );

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Build JavaScript assets for PHP unit tests

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / check

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Run performance tests

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / All

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 2

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 3

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 4

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 6

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 7

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 5

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 8

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Playwright - 1

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.

Check failure on line 200 in packages/editor/src/dataviews/store/private-actions.ts

GitHub Actions / Build Release Artifact

Argument of type 'Field<BasePost> | Field<CommonPost> | Field<Template> | Field<Pattern>' is not assignable to parameter of type 'false | "" | Field<BasePost> | Field<BasePostWithEmbeddedAuthor> | undefined'.
}

registry.batch( () => {