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

Aperta
#6,320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
frontend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
PHP
Stelle
28
Fork
5
Merge medio
2h 59m
PR unite (30g)
942

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Automattic/blocks-engine

Tutte le issue di Automattic/blocks-engine

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.