WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.16k stars 4.05k forks source link

unregisterBlockType very slow when unregistering many blocks #24517

Open ghost opened 3 years ago

ghost commented 3 years ago

Describe the bug I build custom websites for clients. In order to do that, I need to disable all core blocks and only enable my own custom blocks, or reusable blocks made using those custom ones.

I have the following code:

wp.domReady( () => {

    wp.blocks.getBlockTypes().forEach( blockType => {
        if( ! ( blockType.category === 'custom' || blockType.category === 'reusable' ) ) {
            wp.blocks.unregisterBlockType( blockType.name );
        }
    });

} );

This takes about 3.3 seconds to complete. During that time, the editor load process is blocked.

To reproduce Paste the above code in a js file and enqueue it for the block editor.

Expected behavior I understand that unregistering so many blocks creates some overhead, but I imagine it can be done faster.

Editor version (please complete the following information):

Desktop (please complete the following information):

talldan commented 3 years ago

Curious, not sure why it takes so long, but could be worth profiling.