Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,49 +466,6 @@ describe( 'blocks', () => {
} );
} );

// This test can be removed once the polyfill for blockHooks gets removed.
it( 'should polyfill blockHooks using metadata on the client when not set on the server', () => {
const blockName = 'tests/hooked-block';
unstable__bootstrapServerSideBlockDefinitions( {
[ blockName ]: {
category: 'widgets',
},
} );

const blockType = {
title: 'block title',
};
registerBlockType(
{
name: blockName,
blockHooks: {
'tests/block': 'firstChild',
},
category: 'ignored',
},
blockType
);
expect( getBlockType( blockName ) ).toEqual( {
apiVersion: 1,
name: blockName,
save: expect.any( Function ),
title: 'block title',
category: 'widgets',
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
keywords: [],
selectors: {},
supports: {},
styles: [],
variations: [],
blockHooks: {
'tests/block': 'firstChild',
},
} );
} );

it( 'should validate the icon', () => {
const blockType = {
save: noop,
Expand Down
62 changes: 13 additions & 49 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,60 +62,24 @@ function bootstrappedBlockTypes( state = {}, action ) {
case 'ADD_BOOTSTRAPPED_BLOCK_TYPE':
const { name, blockType } = action;
const serverDefinition = state[ name ];
let newDefinition;
// Don't overwrite if already set. It covers the case when metadata
// was initialized from the server.
if ( serverDefinition ) {
// The `blockHooks` prop is not yet included in the server provided
// definitions and needs to be polyfilled. This can be removed when the
// minimum supported WordPress is >= 6.4.
if (
serverDefinition.blockHooks === undefined &&
blockType.blockHooks
) {
newDefinition = {
...serverDefinition,
...newDefinition,
blockHooks: blockType.blockHooks,
};
}

// The `allowedBlocks` prop is not yet included in the server provided
// definitions and needs to be polyfilled. This can be removed when the
// minimum supported WordPress is >= 6.5.
if (
serverDefinition.allowedBlocks === undefined &&
blockType.allowedBlocks
) {
newDefinition = {
...serverDefinition,
...newDefinition,
allowedBlocks: blockType.allowedBlocks,
};
}
} else {
newDefinition = Object.fromEntries(
Object.entries( blockType )
.filter(
( [ , value ] ) =>
value !== null && value !== undefined
)
.map( ( [ key, value ] ) => [
camelCase( key ),
value,
] )
);
newDefinition.name = name;
}

if ( newDefinition ) {
return {
...state,
[ name ]: newDefinition,
};
return state;
}
const newDefinition = Object.fromEntries(
Object.entries( blockType )
.filter(
( [ , value ] ) => value !== null && value !== undefined
)
.map( ( [ key, value ] ) => [ camelCase( key ), value ] )
);
newDefinition.name = name;
return {
...state,
[ name ]: newDefinition,
};

return state;
case 'REMOVE_BLOCK_TYPES':
return omit( state, action.names );
}
Expand Down