Shared navigation entity: editor label-box typography from one menu leaks onto another menu's items in the canvas

Open
#6,320 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
frontend

Research direction

Start with NavigationPatternContext::navigationAnchorBoxes() and GeneratedSupportStylesheetState::navigationEditorTypographyRules(), then compare the editor rules with the frontend rules scoped by navigation instance. Check how NavigationEntityProjection::sharedItemClasses() preserves markers on shared items. Done when each navigation reference in the editor canvas uses its own typography, matching the frontend behavior; the issue names no test file.

Written by the indexing model from the issue text.

Description

Summary

When two menus with the same items are factored into one shared wp_navigation entity, the editor-only label-box typography rule from one menu leaks onto the other menu's items in the editor canvas. A header menu that renders at 14px sans-serif on the frontend renders at 28px in the footer menu's font in the canvas. In the real import this makes items wrap ("My Vlog" breaks onto two lines).

Reduced fixture

D2-shared-nav-typography.html: a header menu (font size set on the li), and a footer menu with the same four links, where each link sits inside li > div > span boxes and has its own 28px Georgia typography.

<!doctype html><html><head><meta charset="utf-8"><title>Menus</title><style>
body{margin:0;font-family:sans-serif}
.top{display:flex;justify-content:flex-end;padding:20px 40px}
.top ul{display:flex;gap:20px;list-style:none;margin:0;padding:0}
.top li{font-size:14px}
.top a{color:#222;text-decoration:none;white-space:nowrap}
footer{padding:20px 40px;background:#f4f4f4}
.side ul{list-style:none;margin:0;padding:0}
.side .box{padding:0 10px;border-bottom:1px solid #ccc}
.side .wrap{display:inline-block}
.side a{font-family:Georgia,serif;font-size:28px;line-height:56px;color:#333;text-decoration:none}
</style></head><body>
<header><nav class="top"><ul>
<li><a href="/">Home</a></li><li><a href="/alpha">Alpha Page</a></li><li><a href="/beta">Beta Page</a></li><li><a href="/gamma">Gamma Page</a></li>
</ul></nav></header>
<main><h1>Welcome</h1><p>Body text.</p></main>
<footer><nav class="side"><ul>
<li><div class="box"><span class="wrap"><a href="/">Home</a></span></div></li><li><div class="box"><span class="wrap"><a href="/alpha">Alpha Page</a></span></div></li><li><div class="box"><span class="wrap"><a href="/beta">Beta Page</a></span></div></li><li><div class="box"><span class="wrap"><a href="/gamma">Gamma Page</a></span></div></li>
</ul></nav></footer>
</body></html>

Observed (1440px window)

header menu item .wp-block-navigation-item__content frontend editor canvas
font-size 14px 28px
font-family sans-serif Georgia, serif
"Alpha Page" width 72px 139px

The footer menu is correct on both surfaces (28px Georgia).

Both references point to one entity. That entity's items carry both menus' anchor subject markers:

<!-- wp:navigation-link {"className":"blocks-engine-navigation-item-15972ce37e04-0 blocks-engine-navigation-anchor-b1869fbf8260-0 blocks-engine-navigation-anchor-43176dbb06d3-0","label":"Home",…} /-->

The editor static-state sheet contains this rule, and it is not scoped to a navigation instance:

.wp-block-navigation .wp-block-navigation-item.blocks-engine-navigation-anchor-43176dbb06d3-0 .wp-block-navigation-item__content{font-family:…Georgia,serif;font-size:…28px;line-height:56px;color:…#333}

In the canvas it matches the header menu's items too, because they render the same entity items with the same marker. On the frontend, the matching rules are scoped with .wp-block-navigation.blocks-engine-navigation-instance-<id>-0, so they only bind inside their own reference.

Root cause

  • NavigationPatternContext::navigationAnchorBoxes() (~L1391–1406) registers editor typography for an anchor that has retained boxes, via GeneratedSupportStylesheetState::registerNavigationEditorTypography().
  • GeneratedSupportStylesheetState::navigationEditorTypographyRules() (~L127–138) emits .wp-block-navigation .wp-block-navigation-item.<anchor-marker> .wp-block-navigation-item__content{…} with no navigation-instance scope.
  • NavigationEntityProjection::sharedItemClasses() (#4982) keeps every reference's subject markers on the shared entity items. Its docblock relies on "its item rules are scoped by its navigation instance, so they bind only inside that reference". That holds for the frontend rules but not for these editor typography rules (#4536).

Expected

The editor canvas renders each navigation reference with its own typography, the same way the frontend does. The editor label-box typography rules should carry the same navigation-instance scope as the frontend rules, or the shared entity should not expose another reference's marker to them.

Related: #4536, #4982, #4386.

Reduced and filed with AI assistance (Claude, via coding agent).

Dominant language
PHP
Stars
28
Forks
5
Avg merge
2h 59m
Merged PRs (30d)
942

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Automattic/blocks-engine

All issues in Automattic/blocks-engine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.