Skip to content

Commit

Permalink
getBlockSettings: avoid memoized selector with clientId
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 29, 2024
1 parent 0395847 commit fe53ba2
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions packages/block-editor/src/store/get-block-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import { applyFilters } from '@wordpress/hooks';
* Internal dependencies
*/
import { getValueFromObjectPath } from '../utils/object';
import {
getBlockParents,
getBlockName,
getSettings,
getBlockAttributes,
} from './selectors';
import { getBlockName, getSettings, getBlockAttributes } from './selectors';

const blockedPaths = [
'color',
Expand Down Expand Up @@ -132,22 +127,17 @@ export function hasMergedOrigins( value ) {

export function getBlockSettings( state, clientId, ...paths ) {
const blockName = getBlockName( state, clientId );
const candidates = clientId
? [
clientId,
...getBlockParents( state, clientId, /* ascending */ true ),
].filter( ( candidateClientId ) => {
const candidateBlockName = getBlockName(
state,
candidateClientId
);
return hasBlockSupport(
candidateBlockName,
'__experimentalSettings',
false
);
} )
: [];
const candidates = [];

if ( clientId ) {
let id = clientId;
do {
const name = getBlockName( state, id );
if ( hasBlockSupport( name, '__experimentalSettings', false ) ) {
candidates.push( id );
}
} while ( ( id = state.blocks.parents.get( id ) ) );
}

return paths.map( ( path ) => {
if ( blockedPaths.includes( path ) ) {
Expand Down

0 comments on commit fe53ba2

Please sign in to comment.