Skip to content

Adjacent dynamic blocks that render empty leave whitespace in their parent container #80667

Open

Description

@hanneslsm

Description

The tags block renders a empty space character, even when no tag exists.
This is a problem, because

  1. the block renders on the page, even if it's not needed
  2. some custom css can't be used, such as :empty { display: none; }

Step-by-step reproduction instructions

  1. add the tags block in a query loop
  2. make sure no tag is added to the post
  3. find the space character

Screenshots, screen recording, code snippet

Screen.Recording.2026-07-24.at.08.32.29.mov

Environment info

  • WP 7.0.2
  • GB 23.6.0

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

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. prachigarg19 commented on Jul 24, 2026

    @prachigarg19
    Contributor

    I tried replicating the issue on my local, however, for me, no block was added when there were no tags available, let me know if I am missing something:

    Image Image

    Tested with version 7.1

  2. hanneslsm commented on Jul 24, 2026

    @hanneslsm
    Author

    Thanks @prachigarg19 for testing! I also dug into it a little bit and asked AI for help. I manually tested and can confirm that the issue does not occur when the Tags block is on its own. It occurs when it is accompanied by another empty sibling block, in my case, an empty Categories block.

    Here is what AI found:

    The Post Terms render callback itself behaves correctly. When no terms exist, it returns an empty string:

    https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/post-terms/index.php#L57-L59

    However, Gutenberg's block serializer joins sibling blocks using two newline characters:

    https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/serializer.tsx#L522-L529

    A minimal reproduction is:

    1. Add a Query Loop.
    2. Add a Group inside the Post Template.
    3. Add two Post Tags blocks as direct children of that Group.
      • Alternatively, use a Categories block and a Tags block, but both must render empty.
    4. Ensure the queried post has no matching terms.
    5. Add the following Additional CSS to the Group:
    &:empty {
    	display: none;
    }
    
    1. Inspect the Group on the frontend.

    Both Post Terms blocks correctly render an empty string. However, the \n\n inserted between the sibling blocks during serialization remains inside the Group:

    <div class="wp-block-group ...">
    
    </div>

    The remaining whitespace text node means that the Group is not considered empty, so :empty does not match.

    With only one Post Tags block, no separator between sibling blocks is generated, which explains why the issue does not reproduce in your test.

    I reproduced this with the same environment as the issue:

    • WordPress 7.0.2

    • Gutenberg 23.6.0

      So, more precisely, the Tags block itself does not appear to render a space. The whitespace comes from the serialization of multiple sibling blocks and remains after those dynamic blocks render an empty string. This may therefore be a more general issue affecting adjacent empty dynamic blocks rather than the Post Tags block specifically.

  3. changed the title [-]Post Tags: Block renders space character, even when no tag is available[/-] [+]Adjacent dynamic blocks that render empty leave whitespace in their parent container[/+] on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] SavingRelated to saving functionality[Package] Blocks/packages/blocks[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions