Fix: Prevent custom links from creating empty block bindings#72134
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. |
|
Ideally we'd have added tests here but given this is a nasty bug let's just test and merge and then follow up to add coverage. |
jeryj
left a comment
There was a problem hiding this comment.
Tested manually with custom links and pages and they are now correctly bound
|
Size Change: +15 B (0%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
|
@jeryj If/when this is ready I'd appreciate you hitting merge so we can land asap 🙏 |
|
Flaky tests detected in 768c2ec. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18317153635
|
|
@cbravobernal This one fixes a bug in the other PR which you are including in RC |
* Fully clear binding when clearing * Go with a simpler approach * Simplify even further * Add test coverage * Add tests for conditional clearBinding and optimize test performance * Fix check for specific binding source Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org>
|
I just cherry-picked this PR to the release/21.8 branch to get it included in the next release: 423ff3c |
…ss#72134) * Fully clear binding when clearing * Go with a simpler approach * Simplify even further * Add test coverage * Add tests for conditional clearBinding and optimize test performance * Fix check for specific binding source Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org>
What
Fixes a bug introduced in #71630 where custom links (static URLs like
www.google.com) were incorrectly getting block binding metadata created, even though they should only be plain static links without any bindings.Why
In #71630, we introduced block bindings for Navigation Link blocks to make entity links (Pages, Posts, etc.) dynamic. However, there was a bug in the implementation:
The Problem:
When creating a custom link by typing a URL directly (e.g.,
www.google.com), the system was callingclearBinding()even though there was never a binding in the first place. This resulted in unnecessary binding metadata being added:Root Cause:
clearBinding()always calledupdateBlockBindings(), regardless of whether a valid binding existed. This polluted the block markup with unnecessary metadata and could potentially cause issues with block validation and rendering.How
Updated the
useEntityBindinghook to add a conditional check before clearing bindings:This ensures we only perform the clear operation when there's an actual binding with a valid source, preventing unnecessary metadata from being created.
Testing
Test Case 1: Custom Link Creation
www.google.commetadataattribute should appear on the block"metadata":{"bindings":{"url":{"source":null,"args":null}}}Test Case 2: Entity Link Creation
"metadata":{"bindings":{"url":{"source":"core/entity","args":{"key":"url"}}}}Test Case 3: Entity Link to Custom Link
Test Case 4: Existing Blocks
Screenshots
N/A - This is a data/markup fix with no visual changes