Unable to cleanly register block into woocommerce-product-elements category. #42927
Replies: 4 comments 7 replies
-
Hi @leewillis77, Thank you for bringing this issue to our attention. Our investigation suggests that your custom plugin tries to register the block before Woo registers the block category. This results in an invalid warning. This is a known issue that arises due to a race condition. We are working on enhancing the developer experience related to registering Woo blocks. Unfortunately, we do not have an estimated time for when this issue will be resolved. However, we have a workaround that should help you eliminate this warning:
I know that this is less than ideal, but currently, probably it's your best bet. I hope the below example will be able to help:
|
Beta Was this translation helpful? Give feedback.
-
Hi; I've read through your comments, and had a play, but I'm afraid I can't see how the change you suggested would work? If I remove the Contents of build folder originally:
Contents of build folder after removing
|
Beta Was this translation helpful? Give feedback.
-
In addition, I'm struggling to see where on the PHP side of things WooCommerce registers the block category? |
Beta Was this translation helpful? Give feedback.
-
It doesn't happen on the PHP side. It happens in the editor via the Blocks API. @danielwrobert and @sunyatasattva, my guess here is that the WooCommerce block categories are being registered closely to when WooCommerce Blocks are being registered which means any extensions that invoke registration after WooCommerce blocks will trigger the error/warning Lee is pointing out here. If this is the case, we could look at splitting out the category registration so it can be loaded earlier in the stack and see if that fixes the issue? |
Beta Was this translation helpful? Give feedback.
-
As part of a WooCommerce extension, we're trying to expose blocks from our plugin within the WooCommerce product elements category, e.g.
However, when we register our block (in PHP since I suspect that's relevant), everything works, ie the block shows up correctly, however we also receive the following warning in the JS console:
The block "xxxx" is registered with an invalid category "woocommerce-product-elements".
To reproduce what we're seeing you can do the following:
npx @wordpress/create-block example-plugin
example-plugin/build/block.json
and set the 'category' to 'woocommerce-product-elements'The block "create-block/example-plugin" is registered with an invalid category "woocommerce-product-elements".
What's the correct way to get the block registered in that category without generating warnings?
Beta Was this translation helpful? Give feedback.
All reactions