Describe the bug
Since WordPress 5.5 the WP_Block class with it's render method has been added. Now render_block is only called for all top-level blocks which calls WP_Block::render, each nested (aka innerBlocks) blocks are created in WP_Block::render as WP_Block instances and only rendered with this method.
This means that hooks from render_block (pre_render_block, render_block_data, render_block_context) only get called for top-level blocks. This leads to multiple problems:
wp-includes/blocks/latest-posts:208 . This method is not called if the Latest Posts block is in a Group block.render_block_data before.My use case:
I'm using the 'render_block_data' method to add some custom information (eg. a helper method which parses the is-style-{style} className from the attributes and sets it as variable on the block data.
I didn't read any documentation about this change, but have to admit I still have to read everything about block contexts.
https://core.trac.wordpress.org/ticket/49926
To reproduce
Steps to reproduce the behavior:
block_core_latest_posts_migrate_categories is not called (actually it's called but not for the core/latest-posts block)This can be reproduced for any nested block and any hook to render_block_data (and the others mentioned above).
Expected behavior
I think all blocks should be passed through the same hooks (pre_render_block, render_block_data) - the same method should be used for nested and top-level blocks.
Editor version (please complete the following information):
I'm experiencing the same issue as well! Would be great if someone could have a look at this.
@noisysocks Any information as to what exactly needs testing? I just spun up the current state of the gutenberg plugin via wp-env and it's still the same. It's also seeable from code as I've described in the OP.
Hey @gaambo! We use Needs Testing for tickets that require a little bit of setup in order to reproduce. The label encourages folks to come back to it e.g. in a triage session.
I just checked and was able to confirm this bug. pre_render_block, render_block_data and render_block_context are only called for top-level blocks which isn't what you would expect from reading those filters' documentation. We probably should be applying these filters inside WP_Block::_construct as well.
Since fixing this will require a Core change, I've moved this ticket into Core Trac: https://core.trac.wordpress.org/ticket/51708