Prevent duplicate registration of core blocks in client (#37350)
* Prevent duplicate registration of core blocks * Add components changelog entry
This commit is contained in:
parent
5a21b3f218
commit
562749b60a
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Prevent duplicate registration of core blocks in client
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { BlockInstance } from '@wordpress/blocks';
|
||||
import { BlockInstance, getBlockType } from '@wordpress/blocks';
|
||||
import {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore We need this to import the block modules for registration.
|
||||
|
@ -29,9 +29,10 @@ const ALLOWED_CORE_BLOCKS = [
|
|||
|
||||
const registerCoreBlocks = () => {
|
||||
const coreBlocks = __experimentalGetCoreBlocks();
|
||||
const blocks = coreBlocks.filter( ( block: BlockInstance ) =>
|
||||
ALLOWED_CORE_BLOCKS.includes( block.name )
|
||||
);
|
||||
const blocks = coreBlocks.filter( ( block: BlockInstance ) => {
|
||||
const isRegistered = !! getBlockType( block.name );
|
||||
return ! isRegistered && ALLOWED_CORE_BLOCKS.includes( block.name );
|
||||
} );
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore An argument is allowed to specify which blocks to register.
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Prevent duplicate registration of core blocks in client
|
|
@ -1,7 +1,13 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { registerCoreBlocks } from '@wordpress/block-library';
|
||||
import { BlockInstance, getBlockType } from '@wordpress/blocks';
|
||||
import {
|
||||
registerCoreBlocks,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore We need this to import the block modules for registration.
|
||||
__experimentalGetCoreBlocks,
|
||||
} from '@wordpress/block-library';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -14,7 +20,14 @@ import { init as initPricing } from '../pricing-block';
|
|||
import { init as initCollapsible } from '../collapsible-block';
|
||||
|
||||
export const initBlocks = () => {
|
||||
registerCoreBlocks();
|
||||
const coreBlocks = __experimentalGetCoreBlocks();
|
||||
const blocks = coreBlocks.filter( ( block: BlockInstance ) => {
|
||||
return ! getBlockType( block.name );
|
||||
} );
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore An argument is allowed to specify which blocks to register.
|
||||
registerCoreBlocks( blocks );
|
||||
|
||||
initName();
|
||||
initSummary();
|
||||
initSection();
|
||||
|
|
Loading…
Reference in New Issue