Pattern Overrides: Button block left empty in original pattern and used as an override throws an error in pattern instances #61303
Labels
[Block] Buttons
Affects the Buttons Block
[Feature] Block bindings
[Feature] Synced Patterns
Related to synced patterns (formerly reusable blocks)
[Status] In Progress
Tracking issues with work in progress
[Type] Bug
An existing feature does not function as intended
Description
If a user creates a pattern with an empty button block that has 'Allow Overrides' enabled, an error is thrown when that pattern is used and text is added to the button.
I believe this happens because the button block outputs nothing when the button block is empty:
gutenberg/packages/block-library/src/button/save.js
Lines 34 to 36 in edb7e4e
But block bindings still tries to update the HTML for the pattern overrides binding without checking that a button is present.
A basic fix might be to check for the presence of a button element, and do nothing if there isn't one, but this leads to a problem that no button block is output when the user specifies text in a pattern instance for an empty button. I'm not sure if we could move this check to a server side render callback to fix the problem?
The reverse is also a problem. If a button is specified in the original pattern with text, but the override removes text, an empty button is output, whereas the button block would usually output nothing.
I think the same could also happen for any other type of block binding, so this is probably not a pattern overrides specific issue.
Step-by-step reproduction instructions
Expected: No error occurs, the button is shown
Actual: An error is thrown
Screenshots, screen recording, code snippet
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: