From fe53ba27974f044ef5076d9b99862cca63c70df2 Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 29 Jan 2024 21:37:06 +0200 Subject: [PATCH] getBlockSettings: avoid memoized selector with clientId --- .../src/store/get-block-settings.js | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/packages/block-editor/src/store/get-block-settings.js b/packages/block-editor/src/store/get-block-settings.js index 819ad51f4b0e9..598754a349718 100644 --- a/packages/block-editor/src/store/get-block-settings.js +++ b/packages/block-editor/src/store/get-block-settings.js @@ -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', @@ -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 ) ) {