diff --git a/packages/edit-site/src/components/start-template-options/index.js b/packages/edit-site/src/components/start-template-options/index.js index bc8017fc32029b..e57a197ecade0b 100644 --- a/packages/edit-site/src/components/start-template-options/index.js +++ b/packages/edit-site/src/components/start-template-options/index.js @@ -32,7 +32,7 @@ function useFallbackTemplateContent( slug, isCustom = false ) { ignore_empty: true, } ), } ).then( ( { content } ) => setTemplateContent( content.raw ) ); - }, [ slug ] ); + }, [ isCustom, slug ] ); return templateContent; } @@ -147,28 +147,28 @@ export default function StartTemplateOptions() { const [ modalState, setModalState ] = useState( START_TEMPLATE_MODAL_STATES.INITIAL ); - const { shouldOpenModel, slug, isCustom, postType } = useSelect( + const { shouldOpenModal, slug, isCustom, postType } = useSelect( ( select ) => { const { getEditedPostType, getEditedPostId } = select( editSiteStore ); const _postType = getEditedPostType(); const postId = getEditedPostId(); - const { - __experimentalGetDirtyEntityRecords, - getEditedEntityRecord, - } = select( coreStore ); + const { getEditedEntityRecord, hasEditsForEntityRecord } = + select( coreStore ); const templateRecord = getEditedEntityRecord( 'postType', _postType, postId ); - - const hasDirtyEntityRecords = - __experimentalGetDirtyEntityRecords().length > 0; + const hasEdits = hasEditsForEntityRecord( + 'postType', + _postType, + postId + ); return { - shouldOpenModel: - ! hasDirtyEntityRecords && + shouldOpenModal: + ! hasEdits && '' === templateRecord.content && 'wp_template' === _postType && ! select( preferencesStore ).get( @@ -185,7 +185,7 @@ export default function StartTemplateOptions() { if ( ( modalState === START_TEMPLATE_MODAL_STATES.INITIAL && - ! shouldOpenModel ) || + ! shouldOpenModal ) || modalState === START_TEMPLATE_MODAL_STATES.CLOSED ) { return null;