Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class WP_Navigation_Block_Renderer {
*/
private static $seen_menu_names = array();

private static function get_inner_blocks_content( $inner_blocks ) {
static $inner_blocks_content = array();
if ( empty( $inner_blocks_content ) ) {
foreach ( $inner_blocks as $inner_block ) {
array_push( $inner_blocks_content, $inner_block->render() );
}
}
return $inner_blocks_content;
}

/**
* Returns whether or not this is responsive navigation.
*
Expand All @@ -61,9 +71,9 @@ private static function is_responsive( $attributes ) {
* @return bool Returns whether or not a navigation has a submenu.
*/
private static function has_submenus( $inner_blocks ) {
foreach ( $inner_blocks as $inner_block ) {
$inner_block_content = $inner_block->render();
$p = new WP_HTML_Tag_Processor( $inner_block_content );
$inner_blocks_content = static::get_inner_blocks_content( $inner_blocks );
Copy link
Member Author

@oandregal oandregal Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we need to do is making suer inner blocks only render once for the navigation block. These are not the changes we need, but it helps demonstrate the impact.

Options:

  1. Refactor the code for the inner blocks to be rendered once at WP_Navigation_Block_Renderer::render.
  2. Cache the inner blocks rendering.

I'd very much prefer 1, given this code is new, and so we can make any modifications to it. Once it's in core we won't. Caching moves the issue from time to memory.

foreach ( $inner_blocks_content as $inner_block_content ) {
$p = new WP_HTML_Tag_Processor( $inner_block_content );
if ( $p->next_tag(
array(
'name' => 'LI',
Expand Down