From 3baaa816af9b6d4b7167ce2f7300b138f0edd9ac Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 24 Sep 2024 17:22:51 +0400 Subject: [PATCH 1/2] Blocks: Don't memoize 'hasContentRoleAttribute' selector --- .../blocks/src/store/private-selectors.js | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/packages/blocks/src/store/private-selectors.js b/packages/blocks/src/store/private-selectors.js index 81bdc1fca2c42..439e6efe9fa04 100644 --- a/packages/blocks/src/store/private-selectors.js +++ b/packages/blocks/src/store/private-selectors.js @@ -219,32 +219,27 @@ export function getBlockBindingsSource( state, sourceName ) { * @param {string} blockTypeName Block type name. * @return {boolean} Whether block type has content role attribute. */ -export const hasContentRoleAttribute = createSelector( - ( state, blockTypeName ) => { - const blockType = getBlockType( state, blockTypeName ); - if ( ! blockType ) { +export const hasContentRoleAttribute = ( state, blockTypeName ) => { + const blockType = getBlockType( state, blockTypeName ); + if ( ! blockType ) { + return false; + } + + return Object.entries( blockType.attributes ).some( + ( [ , { role, __experimentalRole } ] ) => { + if ( role === 'content' ) { + return true; + } + if ( __experimentalRole === 'content' ) { + deprecated( '__experimentalRole attribute', { + since: '6.7', + version: '6.8', + alternative: 'role attribute', + hint: `Check the block.json of the ${ blockTypeName } block.`, + } ); + return true; + } return false; } - - return Object.entries( blockType.attributes ).some( - ( [ , { role, __experimentalRole } ] ) => { - if ( role === 'content' ) { - return true; - } - if ( __experimentalRole === 'content' ) { - deprecated( '__experimentalRole attribute', { - since: '6.7', - version: '6.8', - alternative: 'role attribute', - hint: `Check the block.json of the ${ blockTypeName } block.`, - } ); - return true; - } - return false; - } - ); - }, - ( state, blockTypeName ) => [ - state.blockTypes[ blockTypeName ]?.attributes, - ] -); + ); +}; From 9a1273f0db85da8bbefbb02e90d8a31c48ecf9a9 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 24 Sep 2024 18:57:50 +0400 Subject: [PATCH 2/2] Use object values --- packages/blocks/src/store/private-selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/blocks/src/store/private-selectors.js b/packages/blocks/src/store/private-selectors.js index 439e6efe9fa04..d5665323859e4 100644 --- a/packages/blocks/src/store/private-selectors.js +++ b/packages/blocks/src/store/private-selectors.js @@ -225,8 +225,8 @@ export const hasContentRoleAttribute = ( state, blockTypeName ) => { return false; } - return Object.entries( blockType.attributes ).some( - ( [ , { role, __experimentalRole } ] ) => { + return Object.values( blockType.attributes ).some( + ( { role, __experimentalRole } ) => { if ( role === 'content' ) { return true; }