Skip to content
Prev Previous commit
Next Next commit
Show the placeholder when the block has no blocks in the editor.
  • Loading branch information
ramonjd committed Jan 12, 2024
commit d609677796ad7cd23c91a0f0c4bffb487d707817
27 changes: 7 additions & 20 deletions packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
Warning,
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
useEntityProp,
useEntityBlockEditor,
store as coreStore,
} from '@wordpress/core-data';
import { useEntityProp, useEntityBlockEditor } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';
import { Placeholder, Button } from '@wordpress/components';
import { postContent as icon } from '@wordpress/icons';
Expand Down Expand Up @@ -105,23 +101,14 @@ function EditableContent( { context = {}, clientId } ) {
{ id: postId }
);

const { entityRecord, setInserterIsOpened } = useSelect(
( select ) => {
return {
entityRecord: select( coreStore ).getEntityRecord(
'postType',
postType,
postId
),
setInserterIsOpened:
select( blockEditorStore ).getSettings()
.__experimentalSetIsInserterOpened,
};
},
[ postType, postId ]
const setInserterIsOpened = useSelect(
( select ) =>
select( blockEditorStore ).getSettings()
.__experimentalSetIsInserterOpened,
[]
);

const hasInnerBlocks = !! entityRecord?.content?.raw || blocks?.length;
const hasInnerBlocks = !! blocks?.length;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this line so that the placeholder only cares whether the post content block has any child blocks, and will show even if there's saved post content.

This allows us to show the placeholder in the post editor in template preview mode as well.

Do folks see any downsides here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing E2E tests are real and I think due to this change.

I think maybe reverting this change and then do a quick follow up to this PR to avoid a large change set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 7560cba


const { children, ...props } = useInnerBlocksProps(
useBlockProps( {
Expand Down