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

Opening Edit HTML on container blocks shows error "This block contains unexpected or invalid content" #49095

Open
alvarotrigo opened this issue Mar 15, 2023 · 7 comments · Fixed by #49097
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Bug An existing feature does not function as intended

Comments

@alvarotrigo
Copy link

Description

I add two buttons.
I click on "Edit HTML"
And when I click back to "Edit visually" it shows the error "This block contains unexpected or invalid content" even though I didn't change anything at all.

Something's not right there?

Step-by-step reproduction instructions

  1. Add a "buttons" block.
  2. Add 1 or 2 buttons
  3. click on "Edit HTML"
  4. Now click on "Edit visually"
  5. it shows the error "This block contains unexpected or invalid content" even though I didn't change anything at all.

Screenshots, screen recording, code snippet

Video attached:

buttons-error.mp4

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

@Mamaduka Mamaduka added Needs Testing Needs further testing to be confirmed. [Block] Buttons Affects the Buttons Block labels Mar 15, 2023
@Mamaduka
Copy link
Member

Thanks for contributing, @alvarotrigo!

I can confirm the issue, labeling it as a bug.

Side note: The "Convert to Blocks" action doesn't work when viewing the resolution modal.

Screenshot

CleanShot 2023-03-15 at 17 18 45

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended and removed Needs Testing Needs further testing to be confirmed. labels Mar 15, 2023
@Mamaduka Mamaduka self-assigned this Mar 15, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Mar 15, 2023
@courtneyr-dev
Copy link
Contributor

courtneyr-dev commented Mar 15, 2023

I confirmed as well in WP 6.2 Beta 2. I expanded testing slightly @Mamaduka

  • Toggle a single block to view html and back worked
  • Toggle Buttons block group to html and back did not work
  • Toggle entire post to html and back did work.

@alvarotrigo
Copy link
Author

Any workaround to be able to paste the HTML code to make it recognisable for Gutenberg as buttons?

Trying to convert this to buttons but Gutenberg won't recognise it and instead show it as HTML:

<div class="is-layout-flex wp-block-buttons">
    <div class="wp-block-button">
        <a class="wp-block-button__link wp-element-button" href="https://google.com">Demo1</a>
    </div>
    <div class="wp-block-button">
        <a class="wp-block-button__link wp-element-button" href="https://google.com">Demo2</a>
    </div>
</div>

image

What I'm doing:

  • Opening the code editor (top right > three bullets > code editor)
  • Pasting the HTML
  • Clicking on "Exit code editor" at the top
  • Clicking on "Convert to blocks"
    image
  • It shows as HTML instead of as a editable button
    image

@alvarotrigo
Copy link
Author

Ok, got it!

I just had to add HTML comments <!-- wp:buttons --><!-- /wp:buttons --> and <!-- wp:button --><!-- /wp:button --> wrapping their respective HTML elements.
Now Gutenberg can recognise them.

@gziolo gziolo added the [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation label Mar 19, 2023
@gziolo
Copy link
Member

gziolo commented Apr 18, 2023

It must be some bug with how the parent block gets saved when returning from the code editing mode. I don't see any issues when entering the Code Editor and returning to the Visual Editor from Post Editor. I believe removing these blocks' menu items only hides the problem that will also exist for custom blocks.

@Mamaduka
Copy link
Member

@gziolo, the issue has been around for a while. See #11785.

I agree that disabling the option for the container blocks doesn't solve to underline issue, but at least it makes it harder to break block markup.

@gziolo gziolo changed the title Opening Edit HTML on buttons shows error "This block contains unexpected or invalid content" Opening Edit HTML on container blocks shows error "This block contains unexpected or invalid content" Apr 18, 2023
@gziolo gziolo reopened this Apr 18, 2023
@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. and removed [Block] Buttons Affects the Buttons Block labels Apr 18, 2023
@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Apr 18, 2023
@gziolo
Copy link
Member

gziolo commented Apr 18, 2023

I agree that disabling the option for the container blocks doesn't solve to underline issue, but at least it makes it harder to break block markup.

Let's reopen it with a revised title so we can figure out a general solution for the underlying problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants