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

Block bindings: Improve performance by memo postypes slug. #65705

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 6 additions & 3 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export const ExperimentalEditorProvider = withRegistryProvider(
postTypes: getPostTypes( { per_page: -1 } ),
};
}, [] );
const postTypesSlugs = useMemo( () => {
return postTypes?.map( ( entity ) => entity.slug ) || [];
}, [ postTypes ] );

const shouldRenderTemplate = !! template && mode !== 'post-only';
const rootLevelPost = shouldRenderTemplate ? template : post;
const defaultBlockContext = useMemo( () => {
Expand All @@ -194,8 +198,6 @@ export const ExperimentalEditorProvider = withRegistryProvider(
postContext.postType = 'post';
} else if ( post.slug.split( '-' )[ 0 ] === 'single' ) {
// If the slug is single-{postType}, infer the post type from the slug.
const postTypesSlugs =
postTypes?.map( ( entity ) => entity.slug ) || [];
const match = post.slug.match(
`^single-(${ postTypesSlugs.join( '|' ) })(?:-.+)?$`
);
Expand All @@ -222,9 +224,10 @@ export const ExperimentalEditorProvider = withRegistryProvider(
shouldRenderTemplate,
post.id,
post.type,
post.slug,
postTypesSlugs,
rootLevelPost.type,
rootLevelPost.slug,
postTypes,
] );
const { id, type } = rootLevelPost;
const blockEditorSettings = useBlockEditorSettings(
Expand Down
Loading