Open simonemanfre opened 2 weeks ago
Thanks for reporting this, it's an interesting one!
There was a similar comment about the button block in the forums - https://wordpress.org/support/topic/synced-patterns-override-dont-display-field-when-not-filled-in/. It turns out the button block already has this feature—it doesn't output any markup when there's no content (the behavior is not part of the block bindings feature but built into the block itself). There's some inconsistency across core blocks in what they output when there's no content, I think the button block is in the minority.
It might be that some blocks should work like the button block innately, but I don't know if it should be part of the block bindings feature, as that comes with some issues:
Perhaps something like block states is another future solution for this - https://github.com/WordPress/gutenberg/issues/57719.
Thanks for opening the issue! I agree with @talldan, and I am not sure if it is an issue specific to block bindings. If I am not mistaken, if you create an empty heading (without bindings), it is printed in the frontend. That's why I think it is an issue with the block itself, and not exactly with bindings. For the heading, we should probably add some logic to the PHP rendering here to handle that use case.
Yes I think you are right, this issue should be about Gutenberg and not just block bindings. For example an empty “image” or “featured image” block shows nothing in the HTML, while paragraphs and heading tags are shown empty.
What problem does this address?
When a field in a bound block is empty, the empty markup is printed in the page. It's not a very big problem with paragraph markup, but it can cause a SEO problem with the heading tag.
What is your proposed solution?
Remove the markup when a custom field is empty on a bound block.