-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Block bindings: Ensure the block receives the fully expanded __default bindings when rendering #7394
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
f6cecd3
to
e6d9c31
Compare
There are two failing e2e tests, but they also seem to be failing in trunk. |
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.
This looks good in my testing. It seems to solve the mentioned issue, and the rest of use cases seem to work as expected. Code makes sense to me as well. I just left a small comment about where it could be placed.
I also checked that the unit test fails without the proposed solution, and it passes with it.
cd2f3f0
to
3fa50c2
Compare
src/wp-includes/class-wp-block.php
Outdated
/* | ||
* Update the bindings metadata of the computed attributes. | ||
* This ensures the block receives the expanded __default binding metadata when it renders. | ||
*/ |
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.
/* | |
* Update the bindings metadata of the computed attributes. | |
* This ensures the block receives the expanded __default binding metadata when it renders. | |
*/ | |
/* | |
* Update the bindings metadata of the computed attributes. | |
* This ensures the block receives the expanded __default binding metadata when it renders. | |
*/ |
@@ -272,31 +272,41 @@ public function test_using_symbols_in_block_bindings_value() { | |||
} | |||
|
|||
/** | |||
* Tests if the `__default` attribute is replaced with real attribues for | |||
* Tests if the `__default` attribute is replaced with real attributes for |
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.
❤️
That makes perfect sense to update the |
Committed with https://core.trac.wordpress.org/changeset/59095 |
Trac ticket: https://core.trac.wordpress.org/ticket/62069
Gutenberg issue: WordPress/gutenberg#64688
What
Fixes an issue with the image block when using pattern overrides caused by a bug in the block binding logic.
Why does the bug happen?
The pattern overrides feature is built upon block bindings, and uses a special __default binding that means all block attributes that support binding are bound:
During processing of the bindings, this single __default binding is replaced with the individual binding attributes - e.g.:
In the gutenberg plugin this updated bindings metadata is assigned back to the block before rendering so that the block can reason about which individual attributes are bound:
https://github.com/WordPress/gutenberg/blob/98b8d415830fa9ebf7b4b0a2b95d65b9fd1e813a/lib/compat/wordpress-6.6/blocks.php#L40
This allows blocks like the image block to check whether an individual attribute, like
id
, has a binding:https://github.com/WordPress/gutenberg/blob/98b8d415830fa9ebf7b4b0a2b95d65b9fd1e813a/packages/block-library/src/image/index.php#L31
Unfortunately core doesn't have the same logic to assign the updated binding metadata back to the block before rendering, which means the image block's logic fails. The block only receives the individual
__default
binding in its metadata.How has it been fixed?
The fix in this PR is to ensure that the
process_block_bindings
method returns any updates to the block's binding metadata along with other computed attributes.Prior to rendering, the block's attributes are updated with the result of this method (it's where the binding attribute values are updated for a block):
wordpress-develop/src/wp-includes/class-wp-block.php
Lines 465 to 470 in d8e0544
So this will achieve the same result as the code in the Gutenberg plugin.
Steps for reproduction
wp-image-123
)fetchpriority
(which are missing intrunk
)This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.