Opened 2 years ago
Last modified 7 months ago
#56417 new defect (bug)
Changes from 'render_block_data' filter not always applied to inner blocks
Reported by: | isabel_brison | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Editor | Keywords: | |
Focuses: | Cc: |
Description
When changes are made to $parsed_block['innerContent']
using the 'render_block_data' filter, those changes are only applied to top-level blocks, not to inner blocks.
The issue is how we deal with inner blocks in class WP_Block
's render method: we don't create a new instance between applying the filter and calling render on the inner blockhttps://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-block.php#L241, so changes to innerContent
aren't actually applied.
Ideally we should apply the same logic here as we do in the render_block
function: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/blocks.php#L903.
Change History (4)
#2
@
2 years ago
- Milestone changed from Awaiting Review to Future Release
Do you have some code that demonstrates the problem?
#3
@
2 years ago
Do you have some code that demonstrates the problem?
I have a draft PR: https://github.com/WordPress/gutenberg/pull/43504/files where I'm trying to change a block's inner wrapper in a 'render_block_data' filter so the $block_content passed to the subsequent 'render_block' filter already has those changes. Will that work as a demonstration?
#4
@
7 months ago
Gutenberg now has the ability to randomize order in the Gallery block.
https://github.com/WordPress/gutenberg/pull/57477
This feature is achieved by using render_block_data
hooks and shuffling $parsed_block['innerBlocks']
. However, I found that this feature does not work when blocks are nested.
https://github.com/WordPress/gutenberg/issues/58404#issuecomment-1929138499
I'm concerned that the underlying issue is similar to what was reported in this ticket.
Similar to this problem this hook that gives the image block the data-id
attribute also doesn't seem to work when the blocks are nested.
I haven't looked too deeply into this, but I wonder if in both places, rendering of blocks could be implemented as something like
$html = $blockList->render()
.It'd mean a new
render
function in theWP_Block_List
class, but it would be one way of using the same code in both places and reducing inconsistencies.