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

Dont trigger invalid block on empty HTML content #9546

merged 2 commits into from Sep 13, 2018


None yet
2 participants

johngodley commented Sep 2, 2018

If you edit a block's HTML, delete all the content, and then deselect the block it will trigger an invalid block warning:

edit_post_ wordpress_latest _wordpress

Note that 'empty block toolbar' also shows, and will be fixed in #9501.

This PR changes this so the block is reset to its default state and not marked as invalid. The block's 'empty block toolbar' will then also show correctly:

block editor

This matches the behaviour of the page HTML editor where if you delete a block's HTML it will revert to the default:

html editor

How has this been tested?

An additional set of tests has been added for the block-html.js component which tests existing behaviour as well as the modified behaviour.

This can be manually verified on different block types, and undo still works.

Types of changes

This does affect a block's HTML editor mode and so needs to be thoroughly tested. The difference should only occur when the HTML is empty, otherwise it behaves as currently.


  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
Dont trigger invalid block on empty HTML content
If a block’s HTML is set to the empty string we reset the block to it’s default HTML and mark it as valid. This is more useful than the block becoming invalid and needing additional work to resolve

@johngodley johngodley added the Blocks label Sep 2, 2018

@johngodley johngodley referenced this pull request Sep 2, 2018


Fix empty invalid block showing empty block inserter #9501

0 of 4 tasks complete

Worked great on my tests, and the code changes make sense 👍

@johngodley johngodley added this to the 3.9 milestone Sep 13, 2018

@johngodley johngodley merged commit 4c579ed into master Sep 13, 2018

2 checks passed

codecov/project Absolute coverage decreased by -1.1% but relative coverage increased by +49.76% compared to a2d39d0
continuous-integration/travis-ci/pr The Travis CI build passed

@johngodley johngodley deleted the add/no-warning-on-empty-html branch Sep 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment