Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,23 @@ export default function useNavigationMenuContent( postType, postId ) {
record?.blocks
);

if ( ! navigationBlocks.length ) {
return;
}

const navigationMenuIds = navigationBlocks?.map(
( block ) => block.attributes.ref
);

if ( ! navigationMenuIds?.length ) {
// Dedupe the Navigation blocks, as you can have multiple navigation blocks in the template.
// Also, filter out undefined values, as blocks don't have an id when initially added.
const uniqueNavigationMenuIds = [ ...new Set( navigationMenuIds ) ].filter(
( menuId ) => menuId
);

if ( ! uniqueNavigationMenuIds?.length ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see how this could ever be possible, but better safe than sorry I suppose.

return;
}

return <TemplatePartNavigationMenus menus={ navigationMenuIds } />;
return <TemplatePartNavigationMenus menus={ uniqueNavigationMenuIds } />;
}