[wp-trac] [WordPress Trac] #51612: `render_block_data` for nested blocks - WP_Block::render vs render_block
WordPress Trac
noreply at wordpress.org
Fri Oct 23 07:03:46 UTC 2020
#51612: `render_block_data` for nested blocks - WP_Block::render vs render_block
--------------------------+-----------------------------
Reporter: gaambo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
The changes introduced in #49926 also mean that hooks from `render_block`
(like `pre_render_block`, `render_block_data` and `render_block_context`)
only get called for top-level blocks but not for nested blocks, because
nested blocks are now just created in `WP_Block::render` and not passed
through `render_block`.
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 some data (or
migrate it?) - see `wp-includes/blocks/latest-posts:208`. This method is
not called if the Latest Posts block is inside 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 see any documentation about this change, but have to admit I
still have to read everything about block contexts.
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.
I opened an issue on the Gutenberg Github Repo
(https://github.com/WordPress/gutenberg/issues/25900) but didn't get any
response yet. Since this affects the current WP version without the plugin
as well, I thought I'd open an issue here.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51612>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list