diff --git a/routes/post-type-edit/stage.tsx b/routes/post-type-edit/stage.tsx index 4a182e6401593d..7173833fa1da11 100644 --- a/routes/post-type-edit/stage.tsx +++ b/routes/post-type-edit/stage.tsx @@ -83,24 +83,22 @@ function PostTypeEditStage() { const navigate = useNavigate(); const isAddMode = id === NEW_ID; const postTypeId = parseInt( id, 10 ); - const initialData = useSelect( + const record = useSelect( ( select ) => { - if ( isAddMode ) { - return BLANK_RECORD; - } - // beforeLoad (route.ts) guarantees the record is in cache. - const record = select( - coreStore - ).getEntityRecord< PostTypeRecord >( - 'postType', - USER_POST_TYPE_POST_TYPE, - postTypeId - )!; - return toFormData( record ); + return ( + ! isAddMode && + // beforeLoad (route.ts) guarantees the record is in cache. + select( coreStore ).getEntityRecord< PostTypeRecord >( + 'postType', + USER_POST_TYPE_POST_TYPE, + postTypeId + )! + ); }, [ isAddMode, postTypeId ] ); - + const initialData = + ! isAddMode && record ? toFormData( record ) : BLANK_RECORD; const title = isAddMode ? __( 'Add post type' ) : initialData.title.raw; const commonProps = { initialData, title }; const postTypePageProps: PostTypePageProps = isAddMode diff --git a/routes/taxonomy-edit/stage.tsx b/routes/taxonomy-edit/stage.tsx index d49431259119ca..492af70e26de99 100644 --- a/routes/taxonomy-edit/stage.tsx +++ b/routes/taxonomy-edit/stage.tsx @@ -83,24 +83,22 @@ function TaxonomyEditStage() { const navigate = useNavigate(); const isAddMode = id === NEW_ID; const taxonomyId = parseInt( id, 10 ); - const initialData = useSelect( + const record = useSelect( ( select ) => { - if ( isAddMode ) { - return BLANK_RECORD; - } - // beforeLoad (route.ts) guarantees the record is in cache. - const record = select( - coreStore - ).getEntityRecord< TaxonomyRecord >( - 'postType', - USER_TAXONOMY_POST_TYPE, - taxonomyId - )!; - return toFormData( record ); + return ( + ! isAddMode && + // beforeLoad (route.ts) guarantees the record is in cache. + select( coreStore ).getEntityRecord< TaxonomyRecord >( + 'postType', + USER_TAXONOMY_POST_TYPE, + taxonomyId + )! + ); }, [ isAddMode, taxonomyId ] ); - + const initialData = + ! isAddMode && record ? toFormData( record ) : BLANK_RECORD; const title = isAddMode ? __( 'Add taxonomy' ) : initialData.title.raw; const commonProps = { initialData, title }; const taxonomyPageProps: TaxonomyPageProps = isAddMode