Skip to content

Navigation overlay close button may be displayed twice#76585

Merged
getdave merged 3 commits intotrunkfrom
fix/navigation-overlay-html-close-detection
Mar 18, 2026
Merged

Navigation overlay close button may be displayed twice#76585
getdave merged 3 commits intotrunkfrom
fix/navigation-overlay-html-close-detection

Conversation

@getdave
Copy link
Contributor

@getdave getdave commented Mar 17, 2026

What

When a navigation overlay template part uses a pattern (<!-- wp:pattern {"slug":"..."} /-->) that contained a close block, the close button was displayed twice - once for the close in the pattern and then a fallback. This PR fixes that.

Fixes #76567

Why

The fallback close button must only be shown when the overlay does not already contain a close block. The issue was that if the close block was within a Pattern the fallback detection logic failed to detect it thus leading to the duplication.

How

  • Detect the close block in the rendered overlay HTML using WP_HTML_Tag_Processor
  • Add block_core_navigation_overlay_html_has_close_block() helper
  • Suppress the fallback close button when the overlay HTML contains the close button element

Why not check the block tree?

Pattern blocks are self-closing in the tree (<!-- wp:pattern {"slug":"..."} /-->); their inner content is not expanded there. A check like block_core_navigation_block_tree_has_block_type() never sees the close block inside patterns, so it always reports "no close block" and the fallback is incorrectly added.

Why check rendered HTML?

When the block renders, patterns are resolved and their content is output. The close button appears in the actual HTML. Detecting it there (e.g. via WP_HTML_Tag_Processor) correctly reflects what the user sees. It also accounts for edge cases such as hooks/filters adding close blocks...etc

Testing Instructions

  1. Create a block theme with a navigation overlay template part
  2. Inline close block: Add <!-- wp:navigation-overlay-close /--> directly in the template part. Verify one close button appears.
  3. Pattern with close block: Create a pattern containing the overlay content (including <!-- wp:navigation-overlay-close /-->). Use <!-- wp:pattern {"slug":"theme/navigation-overlay"} /--> in the template part. Verify one close button appears (not two).
  4. No close block: Use an overlay without the close block. Verify the fallback close button appears.

Replace block tree check and pattern resolution with WP_HTML_Tag_Processor
on rendered overlay HTML. Fixes double close button when overlay template
parts use patterns.

Fixes #76567
@github-actions github-actions bot added the [Package] Block library /packages/block-library label Mar 17, 2026
@getdave getdave added [Type] Bug An existing feature does not function as intended [Block] Navigation Affects the Navigation Block [Feature] Navigation Overlays labels Mar 17, 2026
@github-project-automation github-project-automation bot moved this to 🔎 Needs Review in WordPress 7.0 Editor Tasks Mar 17, 2026
@getdave getdave added the Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 17, 2026
@getdave getdave self-assigned this Mar 17, 2026
@getdave getdave requested review from jeryj and scruffian March 17, 2026 14:13
@getdave getdave marked this pull request as ready for review March 17, 2026 14:13
@github-actions
Copy link

github-actions bot commented Mar 17, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: benoitchantre <benoitchantre@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@getdave
Copy link
Contributor Author

getdave commented Mar 17, 2026

@benoitchantre would you be open to testing this fix to your reported bug?

You can test using Playground if that helps?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Gutenberg navigation overlay rendering issue where the fallback close button could be output even when the overlay template part already renders a core/navigation-overlay-close block via a core/pattern, resulting in duplicate close buttons.

Changes:

  • Switch close-button detection from block-tree inspection to rendered overlay HTML inspection (via WP_HTML_Tag_Processor) to correctly handle pattern expansion.
  • Add block_core_navigation_overlay_html_has_close_block() helper for detecting the close button element in rendered overlay HTML.
  • Add PHPUnit coverage for the new HTML-based detection, including the pattern-rendering scenario that triggered #76567.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/block-library/src/navigation/index.php Detects overlay close presence from rendered HTML (works with patterns) and suppresses fallback close button accordingly.
phpunit/blocks/class-wp-navigation-block-renderer-test.php Adds unit tests for the new rendered-HTML close-button detection helper, including pattern output coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Flaky tests detected in ca8ba3e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23214188635
📝 Reported issues:

@benoitchantre
Copy link
Contributor

@benoitchantre would you be open to testing this fix to your reported bug?

You can test using Playground if that helps?

It works! Thank you for the fix.

Tested with the provided Playground link and a custom theme under development.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. I can confirm it works with this test theme: WordPress/community-themes#263

@getdave getdave merged commit 0c33c5c into trunk Mar 18, 2026
39 of 40 checks passed
@getdave getdave deleted the fix/navigation-overlay-html-close-detection branch March 18, 2026 07:19
@github-actions github-actions bot added this to the Gutenberg 22.8 milestone Mar 18, 2026
@github-actions github-actions bot removed the Backport to WP 7.0 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 18, 2026
gutenbergplugin pushed a commit that referenced this pull request Mar 18, 2026
* fix: Use HTML-based detection for navigation overlay close block

Replace block tree check and pattern resolution with WP_HTML_Tag_Processor
on rendered overlay HTML. Fixes double close button when overlay template
parts use patterns.

Fixes #76567

* fix: Apply PHP coding standards to navigation block renderer test

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: benoitchantre <benoitchantre@git.wordpress.org>
@github-actions github-actions bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Mar 18, 2026
@github-actions
Copy link

I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: f1ddd38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Navigation Affects the Navigation Block [Feature] Navigation Overlays [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation overlay close button may be displayed twice

4 participants