gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Copied navigation items (Page Link Block, possiby others) have internal ID that is copied so the navigation context (active classes) are applied to the copy incorrectly

Open caseymilne opened this issue 5 years ago • 1 comments

Description

When a Page Link is made from an existing menu it has an internal "id" which references the menu item ID (presumably). This can be viewed in editor code mode. If you duplicate the Page Link block, it's internal ID is copied. The result is if you copy a nav item it still has the same reference which means on the front-end each copy will appear active when you visit the original link. And when you visit the new link page, it will not be highlighted because the page ID doesn't match the menu ID.

Step-by-step reproduction instructions

  1. Create Navigation Block using existing menu.
  2. Copy Page Link.
  3. Edit the title and the link so the item now appears to be a new and unique item.
  4. Visit the front-end. Click on the original menu item. Observe that both the original and copy are now marked "active" with active classes.
  5. Click the copy menu item. Observe that the copy does not have active classes.

Check the Block Markup in code editor mode, observe that copies and original all share the ID which is later used to render active classes and active paths in the menu renderer.

Screenshots, screen recording, code snippet

Screen recording: https://wordpress.slack.com/files/U024GE23UVD/F02BAMK2SE8/2021-08-13_08-05-38.mkv

Environment info

Latest Gutenberg version from plugin. FSE theme Proto.

Pre-checks

  • [X] I have searched the existing issues.
  • [X] I have tested with all plugins deactivated except Gutenberg.

@getdave

caseymilne avatar Aug 13 '21 13:08 caseymilne

So in testing this seems to work ok now.

The caveat is that when updating the copied version an existing WordPress resource has to be selected as the link destination for the id to be changed. If a URL is entered the id is still retained by the block. This is tracked in #34224 though, so I'll close this issue.

talldan avatar Oct 12 '21 08:10 talldan