Skip to content

One Navigation's submenu makes a later, submenu-free Navigation interactive #82288

Closed

Description

@Jiwoon-Kim

Description

WP_Navigation_Block_Renderer::$has_submenus is a class static that latches to true and
is never reset:

private static $has_submenus = false;

private static function has_submenus( $inner_blocks ) {
	if ( true === static::$has_submenus ) {
		return static::$has_submenus;   // returns another block's answer
	}
	…
	static::$has_submenus = true;
}

Once any Navigation on the page contains a submenu, every Navigation rendered afterwards in
that request is treated as containing one. The value feeds is_interactive():

private static function is_interactive( $attributes, $inner_blocks ) {
	$has_submenus = static::has_submenus( $inner_blocks );
	…
	return ( $has_submenus && ( $open_on_click || $show_submenu_icon ) ) || $is_responsive_menu;
}

which decides both whether to load the interactivity view module:

if ( static::is_interactive( $attributes, $inner_blocks ) ) {
	wp_enqueue_script_module( '@wordpress/block-library/navigation/view' );
}

and whether to run block_core_navigation_add_directives_to_submenu() over the rendered
inner HTML.

So a Navigation block with no submenu, on a page where another Navigation has one, loads the
navigation view module it does not need. The block's own content did not decide this.

The static was added in #58513 (Navigation: Fix performance regression, 2024-02-02) to
avoid re-walking inner blocks. The memoisation is keyed on nothing, so it caches a per-block
answer as a per-request one.

Step-by-step reproduction instructions

The two Navigation blocks have to be distinguishable, so the first one is deliberately
not interactive by itself — it has a submenu but no submenu icon, does not open on
click, and is not responsive. It therefore enqueues nothing on its own, and anything
enqueued afterwards was decided by the second block.

  1. Render a Navigation with a submenu, showSubmenuIcon: false, openSubmenusOnClick: false,
    overlayMenu: "never". Confirm no navigation view module is enqueued.
  2. In the same request, render a second Navigation containing only links, with
    showSubmenuIcon: true and overlayMenu: "never".
  3. Check the script module queue.
$link = '<!-- wp:navigation-link {"label":"Home","url":"/"} /-->';
$sub  = '<!-- wp:navigation-submenu {"label":"More","url":"/m"} -->'
      . '<!-- wp:navigation-link {"label":"Deep","url":"/d"} /--><!-- /wp:navigation-submenu -->';

$quiet_with_sub = '<!-- wp:navigation {"showSubmenuIcon":false,"openSubmenusOnClick":false,"overlayMenu":"never"} -->'
	. $sub . '<!-- /wp:navigation -->';
$plain_with_icon = '<!-- wp:navigation {"showSubmenuIcon":true,"overlayMenu":"never"} -->'
	. $link . '<!-- /wp:navigation -->';

Screenshots, screen recording, code snippet

Two separate PHP processes, because the static cannot be reset within one:

process A   plain nav alone                  : none

process B   quiet submenu nav alone          : none
            then the same plain nav          : @wordpress/block-library/navigation/view

The first Navigation enqueues nothing, which is what makes the third line attributable to
the second Navigation. It is the same block, with the same attributes, in both processes.

Environment info

  • WordPress 7.1, no plugins active, Twenty Twenty-Five
  • Same code in Gutenberg trunk, packages/block-library/src/navigation/index.php

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    on Sep 1, 2026
  2. Jiwoon-Kim commented on Sep 1, 2026

    @Jiwoon-Kim
    ContributorAuthor

    The visible symptom here is a module loaded unnecessarily, which is minor on its own — a
    page with a submenu somewhere was loading it anyway. What makes it worth reporting is that
    the rendering of one block depends on which blocks were rendered before it in the request,
    which is not something a block author, theme author, or test can see from the block.

    Memoising the walk seems reasonable; keying it per block, or resetting it per render(),
    would keep the performance win without the cross-block effect.

  3. added
    [Block] Navigation
    on Sep 2, 2026
  4. added
    [Status] In Progress
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Block] Navigation[Status] In Progress[Type] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions