diff --git a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js index 71d8ce2d8ce9f0..09307393eb399b 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-actions/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-actions/index.js @@ -20,9 +20,9 @@ import { chevronLeftSmall as chevronLeftSmallIcon, page as pageIcon, } from '@wordpress/icons'; -import { useEntityRecord } from '@wordpress/core-data'; import { displayShortcut } from '@wordpress/keycodes'; import { useState, useEffect, useRef } from '@wordpress/element'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -36,20 +36,30 @@ export default function DocumentActions() { } function PageDocumentActions() { - const { hasPageContentFocus, context } = useSelect( - ( select ) => ( { - hasPageContentFocus: select( editSiteStore ).hasPageContentFocus(), - context: select( editSiteStore ).getEditedPostContext(), - } ), + const { hasPageContentFocus, hasResolved, isFound, title } = useSelect( + ( select ) => { + const { + hasPageContentFocus: _hasPageContentFocus, + getEditedPostContext, + } = select( editSiteStore ); + const { getEditedEntityRecord, hasFinishedResolution } = + select( coreStore ); + const context = getEditedPostContext(); + const queryArgs = [ 'postType', context.postType, context.postId ]; + const page = getEditedEntityRecord( ...queryArgs ); + return { + hasPageContentFocus: _hasPageContentFocus(), + hasResolved: hasFinishedResolution( + 'getEditedEntityRecord', + queryArgs + ), + isFound: !! page, + title: page?.title, + }; + }, [] ); - const { hasResolved, editedRecord } = useEntityRecord( - 'postType', - context.postType, - context.postId - ); - const { setHasPageContentFocus } = useDispatch( editSiteStore ); const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false ); @@ -65,7 +75,7 @@ function PageDocumentActions() { return null; } - if ( ! editedRecord ) { + if ( ! isFound ) { return (