-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Extensibility: Make Block Bindings work with editor.BlockEdit
hook
#67370
Conversation
Size Change: -120 B (-0.01%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
b24d527
to
985eb9b
Compare
BlockEdit
so it works with existing hooks
BlockEdit
so it works with existing hookseditor.BlockEdit
hook
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. |
I will investigate further the failing e2e test for the Button block and Post Meta source. We need to ensure that |
I hope that 7c4d983 resolves the issue. |
Flaky tests detected in 5c4ff54. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12090287025
|
packages/block-editor/src/components/block-edit/with-block-bindings-support.js
Show resolved
Hide resolved
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.
Looks good to me 🙂 It makes sense to move the logic directly to the BlockEdit
component. I just left a few minor comments.
packages/block-editor/src/components/block-edit/with-block-bindings-support.js
Show resolved
Hide resolved
packages/block-editor/src/components/block-edit/with-block-bindings-support.js
Show resolved
Hide resolved
if ( ! props.attributes?.metadata?.bindings?.content ) { | ||
return el( BlockEdit, props ); | ||
} |
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.
To avoid affecting other tests where content
is connected, maybe it is safer to provide a unique name for this specific test? For example, checking props.attributes?.metadata?.bindings === 'bindings-inspector-controls'
.
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.
Can you explain how this generic UI control could affect other e2e tests and what the idea is to prevent it? bindings
is an object so I'm not sure how to compare that with a string.
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.
Sorry, I meant metadata?.name
, not metadata?.bindings
.
The idea behind it was that right now it is adding the extra control for all the tests with content bound. I guess it shouldn't affect, but I thought it could be safer to provide a unique property (for example, a name to the block) from tests that need the extra control and check against that instead.
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.
What are other conditions that would get closer to real-life usage? I don't think extenders would ever target their integrations based on the name provided by the user through UI for the block name.
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'd be specific to the test. But it's okay, we can keep the control even for those tests where it is not needed.
👋🏻 Looks like this had a pretty big negative impact on the |
Yes, I will try to fix it tomorrow or revert depending how on how it goes. |
I opened a revert with #67516 to check whether it resolves the performance regression. In the meantime, I will continue investigating locally. |
…ordPress#67370) * Block Bindings: Move the place when the attributes get overriden * Fix failing unit tests * Wrap Edit with bindings logic only when the block supports it * Extend the test plugin with `editor.BlockEdit` filter * Add a new test covering the extensibility inside inspector controls * Fix the issue with missing context established by sources Co-authored-by: gziolo <[email protected]> Co-authored-by: SantosGuillamot <[email protected]>
…67370) * Block Bindings: Move the place when the attributes get overriden * Fix failing unit tests * Wrap Edit with bindings logic only when the block supports it * Extend the test plugin with `editor.BlockEdit` filter * Add a new test covering the extensibility inside inspector controls * Fix the issue with missing context established by sources Co-authored-by: gziolo <[email protected]> Co-authored-by: SantosGuillamot <[email protected]>
What?
It wasn't possible to use
editor.BlockEdit
filter to extend the block with additional controls and successfully usesetAttributes
orattributes
for connected attribute using Block Bindings.Why?
The way all the logic for enhancing
attributes
andsetAttributes
was connected too deep in the React components chain. It was below the point whereeditor.BlockEdit
allows overriding the Edit component. In effect the defaultattributes
andsetAttributes
were passed to the component as if it wasn't connected with Block Bindings mechanism.How?
Refactored the code to move the logic higher in the hierarchy so all required child blocks receive access to enhanced
attributes
andsetAttributes
props.Testing Instructions
I included a new e2e test that covers the extensibility point for
editor.BlockEdit
hooks that uses the enhanced props correctly by consuming them through input field injected into inspector controls:The simplest way to test it is using the Gutenberg Test Block Bindings plugin included with e2e tests:
text_field_value
.Content
.