Navigation overlay close button may be displayed twice#76585
Conversation
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
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@benoitchantre would you be open to testing this fix to your reported bug? You can test using Playground if that helps? |
There was a problem hiding this comment.
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.
|
Flaky tests detected in ca8ba3e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23214188635
|
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>
scruffian
left a comment
There was a problem hiding this comment.
Thanks for the fix. I can confirm it works with this test theme: WordPress/community-themes#263
* 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>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: f1ddd38 |
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
WP_HTML_Tag_Processorblock_core_navigation_overlay_html_has_close_block()helperWhy 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 likeblock_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...etcTesting Instructions
<!-- wp:navigation-overlay-close /-->directly in the template part. Verify one close button appears.<!-- wp:navigation-overlay-close /-->). Use<!-- wp:pattern {"slug":"theme/navigation-overlay"} /-->in the template part. Verify one close button appears (not two).