Skip to content

Commit

Permalink
Template Part: Derive 'hasInnerBlocks' inside selector (#58680)
Browse files Browse the repository at this point in the history
* Template Part: Derive 'hasInnerBlocks' inside selector
* Remove leftover comment

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: draganescu <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent 672b5aa commit 884c494
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,11 @@ export default function TemplatePartEdit( {
const [ isTemplatePartSelectionOpen, setIsTemplatePartSelectionOpen ] =
useState( false );

// Set the postId block attribute if it did not exist,
// but wait until the inner blocks have loaded to allow
// new edits to trigger this.
const { isResolved, innerBlocks, isMissing, area } = useSelect(
const { isResolved, hasInnerBlocks, isMissing, area } = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getBlocks } = select( blockEditorStore );
const { getBlockCount } = select( blockEditorStore );

const getEntityArgs = [
'postType',
Expand All @@ -108,7 +105,7 @@ export default function TemplatePartEdit( {
: false;

return {
innerBlocks: getBlocks( clientId ),
hasInnerBlocks: getBlockCount( clientId ) > 0,
isResolved: hasResolvedEntity,
isMissing:
hasResolvedEntity &&
Expand All @@ -129,7 +126,7 @@ export default function TemplatePartEdit( {
// We don't want to render a missing state if we have any inner blocks.
// A new template part is automatically created if we have any inner blocks but no entity.
if (
innerBlocks.length === 0 &&
! hasInnerBlocks &&
( ( slug && ! theme ) || ( slug && isMissing ) )
) {
return (
Expand Down Expand Up @@ -167,7 +164,7 @@ export default function TemplatePartEdit( {
isEntityAvailable={ isEntityAvailable }
templatePartId={ templatePartId }
defaultWrapper={ areaObject.tagName }
hasInnerBlocks={ innerBlocks.length > 0 }
hasInnerBlocks={ hasInnerBlocks }
/>
</InspectorControls>
{ isPlaceholder && (
Expand Down Expand Up @@ -215,7 +212,7 @@ export default function TemplatePartEdit( {
tagName={ TagName }
blockProps={ blockProps }
postId={ templatePartId }
hasInnerBlocks={ innerBlocks.length > 0 }
hasInnerBlocks={ hasInnerBlocks }
layout={ layout }
/>
) }
Expand Down

1 comment on commit 884c494

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 884c494.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7829427770
📝 Reported issues:

Please sign in to comment.