From 617735dc3e5f19cce97026cbb3e4abe38cc3f3da Mon Sep 17 00:00:00 2001 From: karthikeya-io Date: Wed, 5 Mar 2025 19:03:58 +0530 Subject: [PATCH] Block Directory: Bootstrap all blocks metadata to avoid missing innerblocks of newly installed Block --- packages/block-directory/src/store/actions.js | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/block-directory/src/store/actions.js b/packages/block-directory/src/store/actions.js index 6e8ec13002acb4..317ed2623f4747 100644 --- a/packages/block-directory/src/store/actions.js +++ b/packages/block-directory/src/store/actions.js @@ -87,6 +87,7 @@ export const installBlockType = // Ensures that the block metadata is propagated to the editor when registered on the server. const metadataFields = [ + 'name', 'api_version', 'title', 'category', @@ -103,23 +104,32 @@ export const installBlockType = 'variations', ]; await apiFetch( { - path: addQueryArgs( `/wp/v2/block-types/${ name }`, { + path: addQueryArgs( `/wp/v2/block-types/`, { _fields: metadataFields, } ), } ) // Ignore when the block is not registered on the server. .catch( () => {} ) .then( ( response ) => { - if ( ! response ) { + if ( ! response && ! Array.isArray( response ) ) { return; } - unstable__bootstrapServerSideBlockDefinitions( { - [ name ]: Object.fromEntries( - Object.entries( response ).filter( ( [ key ] ) => - metadataFields.includes( key ) - ) - ), - } ); + const blockDefinitions = Object.fromEntries( + response.map( ( blockItem ) => [ + blockItem.name, + Object.fromEntries( + Object.entries( blockItem ).filter( + ( [ key ] ) => + metadataFields.includes( key ) + ) + ), + ] ) + ); + + // Bootstrap all retrieved block definitions + unstable__bootstrapServerSideBlockDefinitions( + blockDefinitions + ); } ); await loadAssets();