diff --git a/packages/block-editor/src/hooks/block-bindings.js b/packages/block-editor/src/hooks/block-bindings.js index ec7348a981d969..8955183a2a0706 100644 --- a/packages/block-editor/src/hooks/block-bindings.js +++ b/packages/block-editor/src/hooks/block-bindings.js @@ -186,46 +186,38 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => { const bindableAttributes = getBindableAttributes( blockName ); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); - // `useSelect` is used purposely here to ensure `getFieldsList` - // is updated whenever there are attribute updates. - // `source.getFieldsList` may also call a selector via `registry.select`. - const { fieldsList, canUpdateBlockBindings } = useSelect( + const registeredSources = + unlock( blocksPrivateApis ).getBlockBindingsSources(); + + const fieldsList = {}; + Object.entries( registeredSources ).forEach( + ( [ sourceName, { getFieldsList, usesContext } ] ) => { + if ( getFieldsList ) { + const context = usesContext?.reduce( ( _context, key ) => { + _context[ key ] = blockContext[ key ]; + return _context; + }, {} ); + + const sourceList = getFieldsList( { registry, context } ); + if ( sourceList ) { + fieldsList[ sourceName ] = sourceList; + } + } + } + ); + + const { canUpdateBlockBindings } = useSelect( ( select ) => { if ( ! bindableAttributes || bindableAttributes.length === 0 ) { return {}; } - const _fieldsList = {}; - const { getBlockBindingsSources } = unlock( blocksPrivateApis ); - const registeredSources = getBlockBindingsSources(); - Object.entries( registeredSources ).forEach( - ( [ sourceName, { getFieldsList, usesContext } ] ) => { - if ( getFieldsList ) { - // Populate context. - const context = {}; - if ( usesContext?.length ) { - for ( const key of usesContext ) { - context[ key ] = blockContext[ key ]; - } - } - const sourceList = getFieldsList( { - registry, - context, - } ); - // Only add source if the list is not empty. - if ( sourceList ) { - _fieldsList[ sourceName ] = { ...sourceList }; - } - } - } - ); return { - fieldsList: _fieldsList, canUpdateBlockBindings: select( blockEditorStore ).getSettings() .canUpdateBlockBindings, }; }, - [ blockContext, bindableAttributes, registry ] + [ bindableAttributes ] ); // Return early if there are no bindable attributes. if ( ! bindableAttributes || bindableAttributes.length === 0 ) {