Skip to content

Commit

Permalink
Do not setMeta if there are no bound group blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Sep 5, 2024
1 parent 44dbde7 commit 2026ae5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions includes/runtime/src/hooks/use-bound-group-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ export const useBoundGroupExtractor = () => {
const [ , setMeta ] = useEntityProp( 'postType', POST_TYPE, 'meta' );

useEffect( () => {
const boundBlocks = findBoundBlocks( blocks );
const boundBlocks = findBoundGroupBlocks( blocks );

if ( Object.keys( boundBlocks ).length === 0 ) {
return;
}

setMeta( boundBlocks );
}, [ blocks, setMeta ] );

return null;
};

const findBoundBlocks = ( blocks, acc = {} ) => {
const findBoundGroupBlocks = ( blocks, acc = {} ) => {
for ( const block of blocks ) {
if ( 'core/group' !== block.name ) {
continue;
Expand All @@ -32,7 +36,7 @@ const findBoundBlocks = ( blocks, acc = {} ) => {
}

if ( block.innerBlocks.length > 0 ) {
acc = findBoundBlocks( block.innerBlocks, acc );
acc = findBoundGroupBlocks( block.innerBlocks, acc );
}
}

Expand Down

0 comments on commit 2026ae5

Please sign in to comment.