diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index eb61cf89d3d93e..3181b842478c72 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -164,6 +164,17 @@ export function unstable__bootstrapServerSideBlockDefinitions( definitions ) { serverSideBlockDefinitions[ blockName ].apiVersion = definitions[ blockName ].apiVersion; } + // The `ancestor` prop is not included in the definitions shared + // from the server yet, so it needs to be polyfilled as well. + // @see https://github.com/WordPress/gutenberg/pull/39894 + if ( + serverSideBlockDefinitions[ blockName ].ancestor === + undefined && + definitions[ blockName ].ancestor + ) { + serverSideBlockDefinitions[ blockName ].ancestor = + definitions[ blockName ].ancestor; + } continue; } serverSideBlockDefinitions[ blockName ] = mapKeys( @@ -187,6 +198,7 @@ function getBlockSettingsFromMetadata( { textdomain, ...metadata } ) { 'title', 'category', 'parent', + 'ancestor', 'icon', 'description', 'keywords', diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 35a17137ee473d..bda9e864a7ed66 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -415,6 +415,42 @@ describe( 'blocks', () => { } ); } ); + // This test can be removed once the polyfill for ancestor gets removed. + it( 'should apply ancestor on the client when not set on the server', () => { + const blockName = 'core/test-block-with-ancestor'; + unstable__bootstrapServerSideBlockDefinitions( { + [ blockName ]: { + category: 'widgets', + }, + } ); + unstable__bootstrapServerSideBlockDefinitions( { + [ blockName ]: { + ancestor: 'core/test-block-ancestor', + category: 'ignored', + }, + } ); + + const blockType = { + title: 'block title', + }; + registerBlockType( blockName, blockType ); + expect( getBlockType( blockName ) ).toEqual( { + ancestor: 'core/test-block-ancestor', + name: blockName, + save: expect.any( Function ), + title: 'block title', + category: 'widgets', + icon: { src: BLOCK_ICON_DEFAULT }, + attributes: {}, + providesContext: {}, + usesContext: [], + keywords: [], + supports: {}, + styles: [], + variations: [], + } ); + } ); + it( 'should validate the icon', () => { const blockType = { save: noop,