diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index ae12b0cfbcf49d..2f4bab2b5f2589 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -854,14 +854,6 @@ export const registerBlockBindingsSource = ( source ) => { } // Check the `label` property is correct. - if ( label && existingSource?.label ) { - warning( - 'Block bindings "' + - name + - '" source label is already defined in the server.' - ); - return; - } if ( ! label && ! existingSource?.label ) { warning( 'Block bindings source must contain a label.' ); @@ -873,6 +865,10 @@ export const registerBlockBindingsSource = ( source ) => { return; } + if ( label && existingSource?.label && label !== existingSource?.label ) { + warning( 'Block bindings "' + name + '" source label was overriden.' ); + } + // Check the `usesContext` property is correct. if ( usesContext && ! Array.isArray( usesContext ) ) { warning( 'Block bindings source usesContext must be an array.' ); diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 99ca6390d2d3b1..73f310bbf04dc7 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -1512,20 +1512,38 @@ describe( 'blocks', () => { expect( getBlockBindingsSource( 'core/testing' ) ).toBeUndefined(); } ); - it( 'should not override label from the server', () => { + it( 'should override label from the server', () => { // Simulate bootstrap source from the server. registerBlockBindingsSource( { - name: 'core/server', + name: 'core/testing', label: 'Server label', } ); // Override the source with a different label in the client. registerBlockBindingsSource( { - name: 'core/server', + name: 'core/testing', label: 'Client label', } ); expect( console ).toHaveWarnedWith( - 'Block bindings "core/server" source label is already defined in the server.' + 'Block bindings "core/testing" source label was overriden.' ); + const source = getBlockBindingsSource( 'core/testing' ); + unregisterBlockBindingsSource( 'core/testing' ); + expect( source.label ).toEqual( 'Client label' ); + } ); + + it( 'should keep label from the server when not defined in the client', () => { + // Simulate bootstrap source from the server. + registerBlockBindingsSource( { + name: 'core/testing', + label: 'Server label', + } ); + // Override the source with a different label in the client. + registerBlockBindingsSource( { + name: 'core/testing', + } ); + const source = getBlockBindingsSource( 'core/testing' ); + unregisterBlockBindingsSource( 'core/testing' ); + expect( source.label ).toEqual( 'Server label' ); } ); // Check the `usesContext` array is correct. diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index 16594a79271e6c..ac652b91890319 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -403,8 +403,7 @@ export function blockBindingsSources( state = {}, action ) { return { ...state, [ action.name ]: { - // Don't override the label if it's already set. - label: state[ action.name ]?.label || action.label, + label: action.label || state[ action.name ]?.label, usesContext: getMergedUsesContext( state[ action.name ]?.usesContext, action.usesContext