Skip to content

Commit

Permalink
fix(homepage-articles): rendering of placeholder content in WP 6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Oct 11, 2023
1 parent 27340a5 commit a5d4e5b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/blocks/homepage-articles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ type Select = ( namespace: string ) => {
// core/blocks-editor
getBlocks: () => Block[];
// core/editor
getEditorBlocks: () => Block[];
getEditedPostAttribute: ( attribute: string ) => Block[];
// core
getPostTypes: ( query: object ) => null | PostType[];
// STORE_NAMESPACE - TODO: move these to src/blocks/homepage-articles/store.js once it's TS
Expand All @@ -229,19 +229,22 @@ export const postsBlockSelector = (
attributes,
}: { clientId: Block[ 'clientId' ]; attributes: HomepageArticlesAttributes }
): Omit< HomepageArticlesProps, 'attributes' > => {
const { getEditorBlocks } = select( 'core/editor' );
const { getEditedPostAttribute } = select( 'core/editor' );
const editorBlocks = getEditedPostAttribute( 'blocks' ) || [];
const { getBlocks } = select( 'core/block-editor' );
const editorBlocksIds = getEditorBlocksIds( getEditorBlocks() );
const editorBlocksIds = getEditorBlocksIds( editorBlocks );
const blocks = getBlocks();
const isWidgetEditor = blocks.some( block => block.name === 'core/widget-area' );
// The block might be rendered in the block styles preview, not in the editor.
const isWidgetEditor = getBlocks().some( block => block.name === 'core/widget-area' );
const isEditorBlock = editorBlocksIds.indexOf( clientId ) >= 0 || isWidgetEditor;
const isEditorBlock =
editorBlocksIds.length === 0 || editorBlocksIds.indexOf( clientId ) >= 0 || isWidgetEditor;

const { getPosts, getError, isUIDisabled } = select( STORE_NAMESPACE );
const props = {
isEditorBlock,
isUIDisabled: isUIDisabled(),
error: getError( { clientId } ),
topBlocksClientIdsInOrder: getBlocks().map( block => block.clientId ),
topBlocksClientIdsInOrder: blocks.map( block => block.clientId ),
latestPosts: isEditorBlock
? getPosts( { clientId } )
: // For block preview, display static content.
Expand Down

0 comments on commit a5d4e5b

Please sign in to comment.