[wp-trac] [WordPress Trac] #51612: `render_block_data` for nested blocks - WP_Block::render vs render_block
WordPress Trac
noreply at wordpress.org
Tue Aug 24 11:26:51 UTC 2021
#51612: `render_block_data` for nested blocks - WP_Block::render vs render_block
--------------------------------------+-----------------------------
Reporter: gaambo | Owner: (none)
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Future Release
Component: Editor | Version: 5.5
Severity: normal | Resolution:
Keywords: has-unit-tests has-patch | Focuses:
--------------------------------------+-----------------------------
Comment (by gaambo):
I've added a new PR on github to change the `WP_Block::render` method to
use `render_block` for inner blocks as proposed by @azaozz. This fixes the
bug in my test cases.
It can be tested by creating a post/page with a group block and an inner
block (eg paragraph) and adding the code from ticket:51612#comment:4
somewhere (plugin, functions.php) and ensuring it outputs the data for the
group and paragraph block.
I've also written an unit test `test_calls_block_filters_for_inner_blocks`
to prevent future regressions.
The **problem is it breaks two other tests**:
`Tests_Blocks_wpBlock::test_passes_content_to_render_callback` and
`Tests_Blocks_wpBlock::test_render_static_block_type_returns_own_content`.
I've debugged them and the problem is the following:
In these tests a custom block registry instance is passed to the `WP_Block
constructor`. The `WP_Block constructor` get's the `WP_Block_Type`
instance from this registry and saves it in a property of the block
instance. With the proposed changed it now creates a `WP_Block` instance
for each inner block but calls `render_block` in `render`, which creates a
new `WP_Block` instance for the parsed block again. Since `render_block`
has no way of passing a block registry instance it passes none to
(re-)creating the new block instance and then `WP_Block` just assumes the
global block registry. Which lead's to `empty(
$this->block_type->skip_inner_blocks )` (`class-wp-block.php:206`) not
evaluating to true and therefore not calling the render code in this if.
I'm not sure how to go about this. I tried changing all tests to use
`render_block` instead of creating new `WP_Block` instances and rendering
them. But that brings the same problem and I don't think it's a test-
problem but rather an implementation problem.
Another way could be to allow passing a block registry instance to
render_block but I don't know if that's good? Seems we're back to talk
about the use-cases of render_block and WP_Block::render 🤷♂️
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51612#comment:54>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list