The js-file is not executed on time
By the time the DOM load
event is executed the block editor has already parsed the post content and at that time the block wasn’t yet registered so it tells you that it doesn’t exist.
Instead of:
window.addEventListener( 'load', () => {
mcm_register_menu_card_section_block();
});
try:
wp.domReady(mcm_register_menu_card_section_block);
and in the script registration code don’t forget to include the dependencies that the script uses:
wp_register_script(
'mcm-editor-menu-card-section',
plugins_url() . '/mcm/blocks/js/menu_card_section.js',
array(
'wp-blocks',
'wp-dom-ready',
'wp-element',
)
);
Since the script is enqueued by the register_block_type()
function it should actually be in the correct place to begin with and just calling the function directly:
mcm_register_menu_card_section_block();
without domReady
should work as well. How ever using domReady
leaves a window of opportunity for 3rd party plugins to filter the registration should they need to do so. It’s up for debate whether it should be used or not: https://github.com/WordPress/gutenberg/issues/9757