Repository navigation
Conversation
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
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: +59 B (0%) Total Size: 8.21 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsShow the failuresSome 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
|
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VHRpPyD9iAESHJShbvchJH
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
This is a draft placeholder for an AI-created PR. Don't review.
What?
See #82985
Stores a Navigation Link's
typeexactly as the API names the post type or taxonomy, except for the two names the block deliberately spells differently (post_tagastag, and the search API'spost-formataspost_format). The mapping between block types and API names moves into one shared module,navigation-link/shared/link-types.js.Why?
updateAttributesrunsnewType.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'spost-formatinto thepost_formattaxonomy. It also rewrites every other slug with a hyphen in it, so a link to anevent-seriespost is stored asevent_series.Nothing is registered under that name, so the link breaks as soon as it is chosen:
'type' => $entity->name), andisActivecomparestypeexactly, so the block stays a Custom Link instead of becoming an "Event Series link".useEntityBindinglooks the entity up withgetEntityRecord( 'postType', 'event_series', id ), finds nothing, and the sidebar reports the link as invalid.The new e2e test reproduces this on trunk. After choosing an
event-seriespost from the "Link to" search, the sidebar showsLink to: Add link Missing event_seriesand "This link is invalid and will not appear on your site. Please update the link."Only the first hyphen was replaced (
replace, notreplaceAll), so a slug such asmy-custom-typewas stored asmy_custom-type, which no reverse mapping could undo.How?
shared/link-types.jsholds the mapping in one place:toBlockType( apiType )turnspost_tagintotagandpost-formatintopost_format, and returns every other name unchanged.toApiType( blockType )turnstagback intopost_tagfor entity lookups.post_formatis already the taxonomy's name, so it is unchanged; only the search API spells itpost-format, andgetSuggestionsQuerykeeps 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 onlytype), whichgetSuggestionsQuerydid implicitly with itsswitch.updateAttributesstorestoBlockType( newType ).useEntityBindinglooks the entity up bytoApiType( type ).getSuggestionsQueryusesgetLinkKindandtoApiTypeinstead of its own list of types.Links already saved as
event_seriesare left as they are. The rewrite is lossy:event_seriescould have come fromevent-seriesor 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.jswith the samegetLinkKind. The two overlap ingetSuggestionsQueryand in that helper. Whichever lands second should movegetLinkKindintolink-types.jsand import it from there.Open questions for reviewers
event_serieslinks alone, or is a best-effort repair worth it, for example trying the hyphenated name when the stored one matches no post type?updateAttributesstill has its ownisBuiltInTypelist (post,page,tag,category), which leaves outpost_format. It could usegetLinkKind, but that would change what is stored for a post format picked without a kind, so it is not part of this change.updateAttributesanduseEntityBinding, so it gets the fix too. Is there anywhere else that reads the storedtypeand expects the underscore form?Testing Instructions
packages/e2e-tests/plugins/navigation-link-hyphenated-post-type.php(activate "Gutenberg Test Navigation Link Hyphenated Post Type").Automated:
npm run test:unit -- packages/block-library/src/navigation-linknpm 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