Skip to content

Navigation Link: Store post type and taxonomy slugs unchanged - #83163

Draft
jeryj wants to merge 2 commits into
trunkfrom
fix/navigation-link-type-slugs
Draft

jeryj wants to merge 2 commits into
trunkfrom
fix/navigation-link-type-slugs

Conversation

@jeryj

@jeryj jeryj commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Important

This is a draft placeholder for an AI-created PR. Don't review.

What?

See #82985

Stores a Navigation Link's type exactly as the API names the post type or taxonomy, except for the two names the block deliberately spells differently (post_tag as tag, and the search API's post-format as post_format). The mapping between block types and API names moves into one shared module, navigation-link/shared/link-types.js.

Why?

updateAttributes runs newType.replace( '-', '_' ) on every type it stores. That line came in with #31259, which was about custom links, tags and post formats: its purpose was to turn the search API's post-format into the post_format taxonomy. It also rewrites every other slug with a hyphen in it, so a link to an event-series post is stored as event_series.

Nothing is registered under that name, so the link breaks as soon as it is chosen:

  • The block does not match its variation. The PHP variations use the real slug ('type' => $entity->name), and isActive compares type exactly, so the block stays a Custom Link instead of becoming an "Event Series link".
  • useEntityBinding looks the entity up with getEntityRecord( 'postType', 'event_series', id ), finds nothing, and the sidebar reports the link as invalid.
  • The Edit button in the sidebar never appears, because it waits for that record.

The new e2e test reproduces this on trunk. After choosing an event-series post from the "Link to" search, the sidebar shows Link to: Add link Missing event_series and "This link is invalid and will not appear on your site. Please update the link."

Only the first hyphen was replaced (replace, not replaceAll), so a slug such as my-custom-type was stored as my_custom-type, which no reverse mapping could undo.

How?

  • shared/link-types.js holds the mapping in one place:
    • toBlockType( apiType ) turns post_tag into tag and post-format into post_format, and returns every other name unchanged.
    • toApiType( blockType ) turns tag back into post_tag for entity lookups. post_format is already the taxonomy's name, so it is unchanged; only the search API spells it post-format, and getSuggestionsQuery keeps handling that as a search type of its own.
    • getLinkKind( attributes ) infers the kind of a built-in type saved without one (older blocks have only type), which getSuggestionsQuery did implicitly with its switch.
  • updateAttributes stores toBlockType( newType ).
  • useEntityBinding looks the entity up by toApiType( type ).
  • getSuggestionsQuery uses getLinkKind and toApiType instead of its own list of types.

Links already saved as event_series are left as they are. The rewrite is lossy: event_series could have come from event-series or be a real slug with an underscore, so there is no safe way to fix them automatically. Choosing the link again stores the correct slug.

Relation to #82985

#82985 widens the Navigation Link search and adds shared/get-link-kind.js with the same getLinkKind. The two overlap in getSuggestionsQuery and in that helper. Whichever lands second should move getLinkKind into link-types.js and import it from there.

Open questions for reviewers

  • Is it right to leave existing event_series links alone, or is a best-effort repair worth it, for example trying the hyphenated name when the stored one matches no post type?
  • updateAttributes still has its own isBuiltInType list (post, page, tag, category), which leaves out post_format. It could use getLinkKind, but that would change what is stored for a post format picked without a kind, so it is not part of this change.
  • The Navigation Submenu block uses the same updateAttributes and useEntityBinding, so it gets the fix too. Is there anywhere else that reads the stored type and expects the underscore form?

Testing Instructions

  1. Register a public post type with a hyphen in its slug, for example with the new test plugin packages/e2e-tests/plugins/navigation-link-hyphenated-post-type.php (activate "Gutenberg Test Navigation Link Hyphenated Post Type").
  2. Publish an Event Series post called "Summer Fair".
  3. In a post, add a Navigation block with a Custom Link, select the link, and open "Link to" in the block settings.
  4. Search for "Summer Fair" and choose it.
  5. On trunk, the sidebar says the link is invalid and "Missing event_series". With this PR, the block becomes an "Event Series link", the link is valid, and an Edit button appears.

Automated:

  • npm run test:unit -- packages/block-library/src/navigation-link
  • npm run test:e2e -- test/e2e/specs/editor/blocks/navigation.spec.js -g "hyphen in its slug"

Testing Instructions for Keyboard

The same steps work with the keyboard: Tab to the "Link to" button, press Enter, type the title, then use the arrow keys and Enter to choose the result.

Use of AI Tools

This PR was written with Claude Code (Claude Opus 5): the investigation, tests, code and this description. It is opened as a draft to start the discussion and has not yet been reviewed in full by its author.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VHRpPyD9iAESHJShbvchJH

updateAttributes replaced the first hyphen in every type with an
underscore. That was meant for the search API's `post-format` (#31259),
but it also rewrote custom post types and taxonomies: an `event-series`
link was stored as `event_series`. Nothing registers that name, so the
link matched no variation, its entity could not be found, and the
sidebar reported it as invalid.

Move the mapping between block types and API names into
shared/link-types.js and use it from updateAttributes,
useEntityBinding and getSuggestionsQuery. Only `post_tag` and
`post-format` are renamed; every other slug is stored as the API gives
it. Links already saved with the rewritten name are left as they are,
since the original slug cannot be recovered from it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHRpPyD9iAESHJShbvchJH
@github-actions github-actions Bot added [Package] Block library /packages/block-library [Package] E2E Tests /packages/e2e-tests labels Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

📦 Bundle size

Size Change: +59 B (0%)

Total Size: 8.21 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 364 kB +59 B (+0.02%)

382904a Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 6a992f2 trunk % Change
timeToFirstByte 54.25 ms +11.15% -2.3% 54.85 ms +10.85% -3.19% -1.09%
largestContentfulPaint 96 ms +4.17% -8.33% 94 ms +4.26% -10.64% 2.13%
lcpMinusTtfb 34.55 ms +21.27% -7.53% 33.95 ms +23.12% -7.36% 1.77%
wpBeforeTemplate 26.61 ms +19.09% -1.77% 26.58 ms +14.26% -1.84% 0.11%
wpTemplate 23.31 ms +3.17% -4.12% 23.35 ms +4.03% -2.18% -0.17%
wpTotal 50.39 ms +10.93% -2.34% 50.96 ms +10.18% -3.08% -1.12%
wpMemoryUsage 7.53 MB +0% -0% 7.49 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric 6a992f2 trunk % Change
timeToFirstByte 39.3 ms +12.21% -0.25% 43.5 ms +5.63% -1.03% -9.66%
largestContentfulPaint 88 ms +4.55% -0% 96 ms +4.17% -0% -8.33%
lcpMinusTtfb 48.7 ms +0.92% -3.8% 52.85 ms +1.7% -0.66% -7.85%
wpBeforeTemplate 23.17 ms +9.84% -0.3% 23 ms +0.61% -0.7% 0.74%
wpTemplate 13.49 ms +1.85% -1.7% 17.26 ms +2.32% -1.1% -21.84%
wpTotal 36.51 ms +11.64% -0.44% 40.36 ms +5.65% -1.16% -9.54%
wpMemoryUsage 6.01 MB +0% -0% 6.11 MB +0% -0% -1.66%
wpDbQueries 10 +0% -0% 14 +0% -0% -28.57%

media-processing

Metric 6a992f2 trunk % Change
mediaProcessingJpeg 411.66 ms +3.97% -0.83% 408.84 ms +0.52% -0.45% 0.69%
mediaProcessingAvif 6187.27 ms +0.42% -0.08% 6187.95 ms +0.2% -0.02% -0.01%
mediaProcessingJpegToAvif 4306.22 ms +0.33% -0.06% 4321.88 ms +0.06% -0.36% -0.36%

media-upload

Metric 6a992f2 trunk % Change
jpegUploadProcessing 1442.46 ms +36.81% -1.58% 1404.4 ms +1.27% -0.29% 2.71%
pngUploadProcessing 204.41 ms +6.99% -4.86% 201.03 ms +6.93% -2.8% 1.68%
largeJpegUploadProcessing 1399.73 ms +1.69% -0.08% 1412.72 ms +0.38% -0.7% -0.92%
multipleImageUploadProcessing 1546.54 ms +0.89% -0.69% 1523.44 ms +1% -0.94% 1.52%

post-editor

Metric 6a992f2 trunk % Change
serverResponse 515.7 ms +1.05% -11.4% 512.64 ms +5.58% -7.72% 0.6%
firstPaint 273.46 ms +51.32% -35.75% 219.92 ms +8.61% -9.21% 24.35%
domContentLoaded 1061.88 ms +0.95% -1.83% 1096.18 ms +1.06% -2.45% -3.13%
loaded 1063.14 ms +0.95% -1.82% 1097.5 ms +1.05% -2.45% -3.13%
firstContentfulPaint 440.11 ms +2.56% -5.98% 446.97 ms +2.46% -2.6% -1.53%
firstBlock 3228.22 ms +2.21% -1.31% 3244.65 ms +0.56% -1.52% -0.51%
type 19.49 ms +6.93% -5.08% 20.48 ms +1.81% -1.66% -4.83%
typeWithoutInspector 22.2 ms +2.88% -4.73% 19.77 ms +4.7% -3.44% 12.29%
typeWithTopToolbar 26.45 ms +4.27% -2.95% 24.88 ms +5.18% -4.62% 6.31%
typeContainer 8.56 ms +0.35% -5.96% 9.13 ms +5.04% -3.94% -6.24%
focus 76.31 ms +13.79% -6.15% 77.79 ms +8.65% -11.61% -1.9%
firstFocus 218.98 ms +0% -0% 217.69 ms +0% -0% 0.59%
selectAll 525.48 ms +7.97% -4.08% 502.15 ms +6.45% -0.63% 4.65%
listViewOpen 78.06 ms +5.84% -11.85% 75.7 ms +6.22% -11.9% 3.12%
inserterOpen 23.53 ms +10.96% -6.67% 23.66 ms +8.79% -1.52% -0.55%
inserterHover 2.93 ms +8.87% -8.19% 2.97 ms +14.81% -3.7% -1.35%
inserterSearch 7.91 ms +11% -10.24% 8 ms +13% -5.25% -1.12%
loadPatterns 643.46 ms +7.12% -2.93% 664.67 ms +0.35% -2.4% -3.19%
wpTotal 505.39 ms +1.07% -11.51% 502.35 ms +5.78% -7.87% 0.61%
wpMemoryUsage 13.04 MB +0% -0% 13.01 MB +0% -0% 0.28%
wpDbQueries 54 +0% -0% 54 +0% -1.85% 0%

site-editor

Metric 6a992f2 trunk % Change
serverResponse 489.38 ms +4.91% -3.64% 493.45 ms +2.16% -2.67% -0.82%
firstPaint 225.64 ms +19.81% -6.95% 249.94 ms +12.56% -12.82% -9.72%
domContentLoaded 1135.99 ms +1.54% -1.33% 1139.14 ms +1.43% -1.43% -0.28%
loaded 1137.36 ms +1.51% -1.32% 1140.56 ms +1.43% -1.44% -0.28%
firstContentfulPaint 446.26 ms +2.66% -3.31% 445.18 ms +3.83% -0.43% 0.24%
firstBlock 4140.93 ms +2.08% -0.43% 4125.19 ms +0.33% -0.34% 0.38%
type 20.53 ms +3.07% -3.51% 19.63 ms +5.35% -4.58% 4.58%
navigate 122.17 ms +8.29% -10.78% 108.49 ms +14.55% -4.67% 12.61%
loadPatterns 1238.97 ms +4.95% -4.6% 1302.26 ms +1.49% -2.73% -4.86%
loadPages 1057.52 ms +2.45% -1.11% 1045.04 ms +6.33% -1.12% 1.19%
wpTotal 479.99 ms +4.96% -3.82% 483.85 ms +2.26% -2.77% -0.8%
wpMemoryUsage 12.01 MB +0% -0% 11.97 MB +0% -0% 0.31%
wpDbQueries 43 +2.33% -0% 43.5 +1.15% -1.15% -1.15%

382904a Run

🏁 Flaky tests

Show the failures

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.

refuses the drop and uploads nothing in /test/e2e/specs/editor/various/single-file-placeholder-drop.spec.js, passed after 1 failed attempt.
Error: expect(received).toHaveLength(expected)

Expected length: 0
Received length: 2
Received array:  [{"_links": {"about": [{"href": "http://localhost:8889/wp-json/wp/v2/types/attachment"}], "author": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/users/1"}], "collection": [{"href": "http://localhost:8889/wp-json/wp/v2/media"}], "curies": [{"href": "https://api.w.org/{rel}", "name": "wp", "templated": true}], "replies": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/comments?post=242"}], "self": [{"href": "http://localhost:8889/wp-json/wp/v2/media/242", "targetHints": {"allow": ["GET", "POST", "PUT", "PATCH", "DELETE"]}}], "wp:attached-to": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/posts/240", "id": 240, "post_type": "post"}]}, "alt_text": "", "author": 1, "caption": {"rendered": ""}, "class_list": ["post-242", "attachment", "type-attachment", "status-inherit", "hentry", "entry"], "comment_status": "open", "date": "2026-09-18T20:55:52", "date_gmt": "2026-09-18T20:55:52", "description": {"rendered": "<p class=\"attachment\"><a href='http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK-1.png'><img loading=\"lazy\" decoding=\"async\" width=\"10\" height=\"10\" src=\"http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK-1.png\" class=\"attachment-medium size-medium\" alt=\"\" style=\"width:100%;height:100%;max-width:10px;\" /></a></p>
"}, "featured_media": 0, "filename": "10x10_e2e_test_image_z9T8jK-1.png", "filesize": 80, "guid": {"rendered": "http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK-1.png"}, "id": 242, "link": "http://localhost:8889/?attachment_id=242", "media_details": {"file": "2026/09/10x10_e2e_test_image_z9T8jK-1.png", "filesize": 80, "height": 10, "image_meta": {"alt": "", "aperture": "0", "camera": "", "caption": "", "copyright": "", "created_timestamp": "0", "credit": "", "focal_length": "0", "iso": "0", "keywords": [], "orientation": "0", "shutter_speed": "0", "title": ""}, "sizes": {}, "width": 10}, "media_type": "image", "meta": [], "mime_type": "image/png", "modified": "2026-09-18T20:55:52", "modified_gmt": "2026-09-18T20:55:52", "ping_status": "closed", "post": 240, "slug": "10x10_e2e_test_image_z9t8jk-2", "source_url": "http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK-1.png", "status": "inherit", "template": "", "title": {"rendered": "10x10_e2e_test_image_z9T8jK"}, "type": "attachment"}, {"_links": {"about": [{"href": "http://localhost:8889/wp-json/wp/v2/types/attachment"}], "author": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/users/1"}], "collection": [{"href": "http://localhost:8889/wp-json/wp/v2/media"}], "curies": [{"href": "https://api.w.org/{rel}", "name": "wp", "templated": true}], "replies": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/comments?post=241"}], "self": [{"href": "http://localhost:8889/wp-json/wp/v2/media/241", "targetHints": {"allow": ["GET", "POST", "PUT", "PATCH", "DELETE"]}}], "wp:attached-to": [{"embeddable": true, "href": "http://localhost:8889/wp-json/wp/v2/posts/240", "id": 240, "post_type": "post"}]}, "alt_text": "", "author": 1, "caption": {"rendered": ""}, "class_list": ["post-241", "attachment", "type-attachment", "status-inherit", "hentry", "entry"], "comment_status": "open", "date": "2026-09-18T20:55:51", "date_gmt": "2026-09-18T20:55:51", "description": {"rendered": "<p class=\"attachment\"><a href='http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK.png'><img loading=\"lazy\" decoding=\"async\" width=\"10\" height=\"10\" src=\"http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK.png\" class=\"attachment-medium size-medium\" alt=\"\" style=\"width:100%;height:100%;max-width:10px;\" /></a></p>
"}, "featured_media": 0, "filename": "10x10_e2e_test_image_z9T8jK.png", "filesize": 80, "guid": {"rendered": "http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK.png"}, "id": 241, "link": "http://localhost:8889/?attachment_id=241", "media_details": {"file": "2026/09/10x10_e2e_test_image_z9T8jK.png", "filesize": 80, "height": 10, "image_meta": {"alt": "", "aperture": "0", "camera": "", "caption": "", "copyright": "", "created_timestamp": "0", "credit": "", "focal_length": "0", "iso": "0", "keywords": [], "orientation": "0", "shutter_speed": "0", "title": ""}, "sizes": {}, "width": 10}, "media_type": "image", "meta": [], "mime_type": "image/png", "modified": "2026-09-18T20:55:51", "modified_gmt": "2026-09-18T20:55:51", "ping_status": "closed", "post": 240, "slug": "10x10_e2e_test_image_z9t8jk", "source_url": "http://localhost:8889/wp-content/uploads/2026/09/10x10_e2e_test_image_z9T8jK.png", "status": "inherit", "template": "", "title": {"rendered": "10x10_e2e_test_image_z9T8jK"}, "type": "attachment"}]
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/single-file-placeholder-drop.spec.js:71:45

382904a Run

This branch has not been deployed

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

Labels

[Package] Block library /packages/block-library [Package] E2E Tests /packages/e2e-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant