Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_block_data for nested blocks - WP_Block::render vs render_block #25900

Closed
gaambo opened this issue Oct 7, 2020 · 3 comments
Closed

render_block_data for nested blocks - WP_Block::render vs render_block #25900

gaambo opened this issue Oct 7, 2020 · 3 comments
Labels
[Feature] Blocks Overall functionality of blocks [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.

Comments

@gaambo
Copy link
Contributor

gaambo commented Oct 7, 2020

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:

  1. There's an inconsistency in rendering depending on if a block is used top-level or in another block (eg group). This may lead to bugs.
  2. Also the Latest Posts block uses this hook to parse som data (or migrate it?) - see wp-includes/blocks/latest-posts:208 . This method is not called if the Latest Posts block is in a Group block.
  3. I'm not sure I can give the same information to a block via block-context as with 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
#21467

To reproduce
Steps to reproduce the behavior:

  1. Create a new Post and insert a Group block
  2. Insert a nested Latest Posts Block
  3. 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):

  • WordPress version: 5.5
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? default
  • If the Gutenberg plugin is installed, which version is it? -
@noisysocks noisysocks added [Feature] Blocks Overall functionality of blocks Needs Testing Needs further testing to be confirmed. labels Oct 26, 2020
@edmundcwm
Copy link
Contributor

I'm experiencing the same issue as well! Would be great if someone could have a look at this.

@gaambo
Copy link
Contributor Author

gaambo commented Nov 4, 2020

@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.

@noisysocks
Copy link
Member

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

@noisysocks noisysocks added [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. and removed Needs Testing Needs further testing to be confirmed. labels Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.
Projects
None yet
Development

No branches or pull requests

3 participants