From df07124dda112be5d3ad1117743970dd75a8a105 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:37:38 +0200 Subject: [PATCH 1/3] Improve performance by memo postypes slug --- packages/editor/src/components/provider/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 0c45dbc5e7199..dc85ce9de5890 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -194,8 +194,11 @@ 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 postTypesSlugs = useMemo( () => { + return ( + postTypes?.map( ( entity ) => entity.slug ) || [] + ); + }, [] ); const match = post.slug.match( `^single-(${ postTypesSlugs.join( '|' ) })(?:-.+)?$` ); From caa2f493c53c1082d96dd8a7e761b7ed2d737aeb Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:35:30 +0200 Subject: [PATCH 2/3] Second try --- packages/editor/src/components/provider/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index dc85ce9de5890..cc6e906368c95 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -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( () => { @@ -194,11 +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 = useMemo( () => { - return ( - postTypes?.map( ( entity ) => entity.slug ) || [] - ); - }, [] ); const match = post.slug.match( `^single-(${ postTypesSlugs.join( '|' ) })(?:-.+)?$` ); From 1afb0d5cd25da3b8dab0b6e62199053f72b0f8f6 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:49:42 +0200 Subject: [PATCH 3/3] Add dependencies --- packages/editor/src/components/provider/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index cc6e906368c95..53cba80543759 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -224,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(