Skip to content

Commit

Permalink
Navigation: Try improving performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Apr 28, 2022
1 parent 9605f3c commit 1f31dfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
13 changes: 5 additions & 8 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ export default function NavigationLinkEdit( {
const {
getBlock,
getBlocks,
getBlockCount,
getBlockName,
getBlockRootClientId,
getClientIdsOfDescendants,
hasSelectedInnerBlock,
getSelectedBlockClientId,
getBlockParentsByBlockName,
Expand All @@ -442,9 +442,6 @@ export default function NavigationLinkEdit( {

const selectedBlockId = getSelectedBlockClientId();

const descendants = getClientIdsOfDescendants( [ clientId ] )
.length;

return {
innerBlocks: getBlocks( clientId ),
isAtMaxNesting:
Expand All @@ -463,10 +460,10 @@ export default function NavigationLinkEdit( {
clientId,
false
),
hasDescendants: !! descendants,
selectedBlockHasDescendants: !! getClientIdsOfDescendants( [
selectedBlockId,
] )?.length,
hasDescendants: !! getBlockCount( clientId ),
selectedBlockHasDescendants: !! getBlockCount(
selectedBlockId
),
userCanCreatePages: select( coreStore ).canUser(
'create',
'pages'
Expand Down
12 changes: 4 additions & 8 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,19 @@ export default function NavigationSubmenuEdit( {
} = useSelect(
( select ) => {
const {
getClientIdsOfDescendants,
hasSelectedInnerBlock,
getSelectedBlockClientId,
getBlockParentsByBlockName,
getBlock,
getBlockCount,
getBlockOrder,
} = select( blockEditorStore );

let _onlyDescendantIsEmptyLink;

const selectedBlockId = getSelectedBlockClientId();

const descendants = getClientIdsOfDescendants( [ clientId ] )
.length;

const selectedBlockDescendants = getClientIdsOfDescendants( [
selectedBlockId,
] );
const selectedBlockDescendants = getBlockOrder( selectedBlockId );

// Check for a single descendant in the submenu. If that block
// is a link block in a "placeholder" state with no label then
Expand All @@ -360,7 +356,7 @@ export default function NavigationSubmenuEdit( {
clientId,
false
),
hasDescendants: !! descendants,
hasDescendants: !! getBlockCount( clientId ),
selectedBlockHasDescendants: !! selectedBlockDescendants?.length,
userCanCreatePages: select( coreStore ).canUser(
'create',
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function NavigationInnerBlocks( {
} = useSelect(
( select ) => {
const {
getClientIdsOfDescendants,
getBlockCount,
hasSelectedInnerBlock,
getSelectedBlockClientId,
} = select( blockEditorStore );
Expand All @@ -60,9 +60,9 @@ export default function NavigationInnerBlocks( {
clientId,
false
),
selectedBlockHasDescendants: !! getClientIdsOfDescendants( [
selectedBlockId,
] )?.length,
selectedBlockHasDescendants: !! getBlockCount(
selectedBlockId
),

// This prop is already available but computing it here ensures it's
// fresh compared to isImmediateParentOfSelectedBlock.
Expand Down

0 comments on commit 1f31dfa

Please sign in to comment.