Skip to content

Conversation

@ockham
Copy link
Contributor

@ockham ockham commented Sep 16, 2025

What?

Fix a bug in the Block Bindings compat layer (which was introduced in #71389).

Why?

See #71483 (comment). In short, pattern overrides would break for the Image block if Block Bindings support was added for another Image block attribute (like caption in case of #71483).

How?

When updating $instance->attributes, merge the computed attributes with $instance->attributes instead of $instance->parsed_block['attrs']. (In hindsight, this one was a silly mistake.)

Additionally, the logic in the code relies on the fact that array_merge doesn't do recursive merges (but replaces $instance->attributes['metadata'] with $computed_attributes['metadata'], thus overriding block bindings that have already been processed). See the inline comments for more details.

Testing Instructions

See #71483 (comment): Check out that PR's branch locally and try to reproduced the bug. Then, cherry-pick the commit from this branch on top. Verify that the bug is fixed.

Note that I've opted to file a separate PR to fix this bug instead of including the fix in #71483 for added visibility, and to avoid e.g. losing the bugfix in case #71483 gets reverted.

@ockham ockham self-assigned this Sep 16, 2025
@ockham ockham added [Type] Bug An existing feature does not function as intended [Feature] Block bindings labels Sep 16, 2025
@ockham ockham force-pushed the fix/block-bindings-compat-layer branch from e1ad423 to ec404de Compare September 16, 2025 08:50
@ockham ockham marked this pull request as ready for review September 16, 2025 08:55
@github-actions
Copy link

github-actions bot commented Sep 16, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ockham
Copy link
Contributor Author

ockham commented Sep 16, 2025

Looks like this introduced a small regression. I'll look into it now.

@gziolo
Copy link
Member

gziolo commented Sep 16, 2025

Looks like this introduced a small regression. I'll look into it now.

I didn't spot any regressions. I can confirm it fixes the issue that I reported with the Image block in Pattern Overrides.

@ockham
Copy link
Contributor Author

ockham commented Sep 16, 2025

Looks like this introduced a small regression. I'll look into it now.

I should've added what it is: One of the unit tests is failing reproducibly (since the change now returns a capitalized <DIV> for the button block rather than a <div>).

@gziolo
Copy link
Member

gziolo commented Sep 16, 2025

It sounds like a test issue which needs to be fixed but it shouldn't require re-testing on my side 👍🏻

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

Flaky tests detected in 6a488fe.
Some 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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17775412209
📝 Reported issues:

@ockham ockham added the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Sep 16, 2025
@ockham
Copy link
Contributor Author

ockham commented Sep 16, 2025

@kmanijak kindly DM'ed me to tell me that the latest GB version seems to throw warnings related to the bug that this PR fixes:

Warning: Undefined array key “attrs” in lib/compat/wordpress-6.9/block-bindings.php on line 25

I've added the "Backport to Gutenberg Minor Release" accordingly.

@ockham ockham merged commit dccfac1 into trunk Sep 16, 2025
68 checks passed
@ockham ockham deleted the fix/block-bindings-compat-layer branch September 16, 2025 19:21
@github-actions github-actions bot added this to the Gutenberg 21.7 milestone Sep 16, 2025
@ellatrix ellatrix removed the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Oct 14, 2025
@ellatrix
Copy link
Member

Looks like this was never put in a minor? I'm removing the label since it's now in the major versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Block bindings [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants