Skip to content

Pattern Overrides: Button block left empty in original pattern and used as an override throws an error in pattern instances #61303

@talldan

Description

@talldan

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:

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

  1. Create a synced pattern with an empty button block (no text defined)
  2. Allow overrides for the button block
  3. Save the pattern
  4. Create a new post and insert the pattern you just created
  5. Enter some text into the button
  6. 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions