-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix Navigation Link broken state when bound entity is deleted #73142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +480 B (+0.02%) Total Size: 2.42 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in b56680f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19236277282
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the Navigation Link block to properly handle deleted entity bindings. When a linked Post/Page is deleted, the block now displays a clear error state with an actionable UI instead of remaining in a broken "partially bound" state.
Key Changes:
- Added entity availability detection to distinguish between valid bindings and deleted entities
- Implemented error state UI with clear messaging and one-click unsync functionality
- Auto-opens Link UI when deleted entity is detected to guide users toward fixing the issue
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
packages/block-library/src/navigation-link/shared/use-entity-binding.js |
Added entity availability checking via useSelect, introducing isBoundEntityAvailable and isBindingActive properties to distinguish between existing bindings with missing entities vs. active valid bindings |
packages/block-library/src/navigation-link/shared/controls.js |
Updated UI to show error state when entity is unavailable: empty input value, error message, enabled input with click-to-unsync functionality, and new MissingEntityHelpText component |
packages/block-library/src/navigation-link/link-ui/index.js |
Updated to use isBindingActive instead of checking binding metadata directly, ensuring Link UI only locks when binding exists AND entity is available |
packages/block-library/src/navigation-link/editor.scss |
Added CSS for error state styling, making the entire input clickable to trigger unsync when entity is missing |
packages/block-library/src/navigation-link/edit.js |
Enhanced useIsInvalidLink to detect deleted entities, added auto-clear URL and Link UI opening logic when deleted entity is detected on block selection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This message only appears when the post/page is deleted permanently - should we also show it when the entity is in trash? |
It's a good question. We have a similar thing with For Trash I believe we show I think we should try as much as possible to limit the scope of this PR if it's got any chance of making 6.9. |
| // Keep binding and ID so invalid state remains visible | ||
| setAttributes( { | ||
| url: undefined, | ||
| } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to clear the invalid URL? I don't love seeing effects that set attributes. What's the harm in keeping it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole effect wasn't needed.
|
I noticed that the link gets removed when I click onto it and then off it: Screen.Recording.2025-11-11.at.09.24.12.mov |
|
Adding the label so it gets more eyes. |
packages/block-library/src/navigation-link/shared/use-entity-binding.js
Outdated
Show resolved
Hide resolved
…ck-editor wasn't being mocked, causing a "is not a function" error.
Changes made to /Users/ben/Sites/gutenberg/packages/block-library/src/navigation-link/shared/test/use-entity-binding.js:
1. Added useBlockEditingMode to the @wordpress/block-editor mock (line 21)
2. Added mock for useSelect by mocking @wordpress/data/src/components/use-select specifically (lines 24-28), following the pattern used in other navigation tests
3. Set up default return values in beforeEach:
- useBlockEditingMode.mockReturnValue('default') (line 43)
- useSelect.mockReturnValue(true) (line 44)
The test "handles invalid kind gracefully in createBinding" now passes, along with all other tests in the file (17/17 passing).
scruffian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is looking good now. Thanks for all your work on it.
I fixed this btw. |
|
There was a conflict while trying to cherry-pick the commit to the wp/6.9 branch. Please resolve the conflict manually and create a PR to the wp/6.9 branch. PRs to wp/6.9 are similar to PRs to trunk, but you should base your PR on the wp/6.9 branch instead of trunk. |
Co-authored-by: getdave <[email protected]> Co-authored-by: scruffian <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: ockham <[email protected]> Co-authored-by: ryanwelcher <[email protected]> Co-authored-by: t-hamano <[email protected]>
|
Manually cherry-picked in d7dd02f. |
|
(I cherry-picked two bug fixes to the file that was causing conflicts.) |
What?
Closes #72564
Fixes Navigation Link block to properly handle deleted entity bindings. When a Post/Page linked via dynamic binding is deleted, the block now shows a clear error state with actionable UI instead of a broken "part bound" state.
Why?
Previously, when a Navigation Link was bound to a Post/Page that was subsequently deleted, the link UI would display in a broken state:
This created a poor user experience where users couldn't understand why their link was broken or how to fix it.
How?
When a Navigation Link's bound entity is deleted:
In the Inspector Sidebar:
In the Canvas:
User Flow:
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Screen.Capture.on.2025-11-10.at.15-12-55.1.mp4