-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
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
if ( RichText.isEmpty( text ) ) { | |
return null; | |
} |
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
- Create a synced pattern with an empty button block (no text defined)
- Allow overrides for the button block
- Save the pattern
- Create a new post and insert the pattern you just created
- Enter some text into the button
- Preview the post
Expected: No error occurs, the button is shown
Actual: An error is thrown
Screenshots, screen recording, code snippet
Warning: foreach() argument must be of type array|object, null given in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/blocks.php on line 84 Deprecated: strcasecmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/blocks.php on line 91 Notice: Function WP_HTML_Tag_Processor::seek was called incorrectly. Unknown bookmark name. Please see Debugging in WordPress for more information. (This message was added in version 6.2.0.) in /var/www/html/wp-includes/functions.php on line 6080 Deprecated: strcasecmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.5/blocks.php on line 91 Notice: Function WP_HTML_Tag_Processor::seek was called incorrectly. Unknown bookmark name. Please see Debugging in WordPress for more information. (This message was added in version 6.2.0.) in /var/www/html/wp-includes/functions.php on line 6080
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