Skip to content

Plain HTML comments between blocks in patterns/templates cause "unexpected or invalid content" error in Site Editor #76526

@369work

Description

@369work

Description

Describe the bug

Adding plain HTML comments (<!-- -->) inside block theme pattern files
(patterns/*.php) or template files (templates/*.html) causes the
"This block contains unexpected or invalid content" error in the Site Editor.
When this error occurs, the affected blocks cannot be edited in the visual editor.

Step-by-step reproduction instructions

To Reproduce

  1. Create a block theme with a patterns/ or templates/ directory

  2. Add a plain HTML comment inside a pattern or template file, e.g.:

    Page not found

  3. Open the

Image Image Image Image

template in the Site Editor
4. The block displays "This block contains unexpected or invalid content"
and cannot be edited in the visual editor

Screenshots

(screenshot attached)

Expected behavior

Plain HTML comments that do not match the block delimiter syntax
(<!-- wp:blockname -->) should be ignored by the block parser
and should not cause block validation errors.

Is there a recommended way to add plain comments inside pattern or
template files without triggering this error?

Screenshots, screen recording, code snippet

No response

Environment info

Environment

  • WordPress version: 6.9 - 7.0beta5
  • Browser: Chrome / Edge

Related issue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions