Skip to content

Commit

Permalink
Site Editor: Avoid stale navigation block values when parsing entity …
Browse files Browse the repository at this point in the history
…record (#54996)
  • Loading branch information
Mamaduka authored Oct 4, 2023
1 parent ac81cda commit b4c0938
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import TemplatePartNavigationMenus from './template-part-navigation-menus';
import useEditedEntityRecord from '../use-edited-entity-record';
import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants';

function getBlocksFromRecord( record ) {
if ( record?.blocks ) {
return record?.blocks;
}

return record?.content && typeof record.content !== 'function'
? parse( record.content )
: [];
}

/**
* Retrieves a list of specific blocks from a given tree of blocks.
*
Expand Down Expand Up @@ -60,11 +70,7 @@ export default function useNavigationMenuContent( postType, postId ) {
return;
}

const blocks =
record?.content && typeof record.content !== 'function'
? parse( record.content )
: [];

const blocks = getBlocksFromRecord( record );
const navigationBlocks = getBlocksOfTypeFromBlocks(
'core/navigation',
blocks
Expand Down

0 comments on commit b4c0938

Please sign in to comment.