From 93a4756b4a2ac21f947d5ca385deaa1591b01e91 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 3 Oct 2023 10:05:53 +0400 Subject: [PATCH] Site Editor: Avoid stale navigation block values when parsing entity record --- .../use-navigation-menu-content.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js index 6c44ea5fbc9bbe..249124b1054cec 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js @@ -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. * @@ -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