Skip to content
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

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

Open
talldan opened this issue May 2, 2024 · 1 comment
Labels
[Block] Buttons Affects the Buttons Block [Feature] Block bindings [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Bug An existing feature does not function as intended

Comments

@talldan
Copy link
Contributor

talldan commented May 2, 2024

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

@talldan talldan added [Type] Bug An existing feature does not function as intended [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Block] Buttons Affects the Buttons Block [Feature] Block bindings labels May 2, 2024
@SantosGuillamot
Copy link
Contributor

I think the same could also happen for any other type of block binding, so this is probably not a pattern overrides specific issue.

I agree this doesn't seem specific to pattern overrides but to all block bindings.

Right now, it seems to me that each block should specify what to do when the value of an attribute is empty/null during the rendering (after bindings are processed). I'm inclined to think that we might need a render_callback for the button block as we have for the heading or the image blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Feature] Block bindings [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants