diff --git a/packages/editor/src/components/post-format/index.js b/packages/editor/src/components/post-format/index.js index 83c6fa6ca5ce1f..bd66e74cab41ec 100644 --- a/packages/editor/src/components/post-format/index.js +++ b/packages/editor/src/components/post-format/index.js @@ -33,19 +33,20 @@ export default function PostFormat() { const instanceId = useInstanceId( PostFormat ); const postFormatSelectorId = `post-format-selector-${ instanceId }`; - const { postFormat, suggestedFormat, supportedFormats } = useSelect( + const { currentFormat, suggestedFormat, supportedFormats } = useSelect( ( select ) => { const themeSupportedFormats = select( 'core' ).getThemeSupports().formats ?? []; const { getEditedPostAttribute, getSuggestedPostFormat } = select( 'core/editor' ); - const _postFormat = getEditedPostAttribute( 'format' ); + const _currentFormat = + getEditedPostAttribute( 'format' ) ?? 'standard'; // Ensure current format is always in the set. // The current format may not be a format supported by the theme. const _supportedFormats = union( - [ _postFormat ], + [ _currentFormat ], themeSupportedFormats ); @@ -53,17 +54,20 @@ export default function PostFormat() { // to check to make sure. const potentialSuggestedFormat = getSuggestedPostFormat(); + // If the suggested format isn't null, isn't already applied, and is + // supported by the theme, return it. Otherwise, return null. let supportedSuggestedFormat = null; if ( potentialSuggestedFormat && + potentialSuggestedFormat !== _currentFormat && _supportedFormats.includes( potentialSuggestedFormat ) ) { supportedSuggestedFormat = potentialSuggestedFormat; } return { - postFormat: _postFormat ?? 'standard', + currentFormat: _currentFormat, supportedFormats: _supportedFormats, suggestedFormat: supportedSuggestedFormat, }; @@ -83,7 +87,7 @@ export default function PostFormat() { { __( 'Post Format' ) } ( { @@ -93,7 +97,7 @@ export default function PostFormat() { /> - { suggestedFormat && suggestedFormat !== postFormat && ( + { suggestedFormat && (
{ __( 'Suggestion:' ) }{ ' ' }