Skip to content

Commit

Permalink
Blocks: Don't memoize 'hasContentRoleAttribute' selector (WordPress#6…
Browse files Browse the repository at this point in the history
…5617)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: getdave <[email protected]>
  • Loading branch information
6 people authored Sep 24, 2024
1 parent 203880a commit f56dbeb
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions packages/blocks/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.values( 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,
]
);
);
};

0 comments on commit f56dbeb

Please sign in to comment.