Block validation triggers when reverting a class change #8131
Labels
[Feature] Blocks
Overall functionality of blocks
[Type] Bug
An existing feature does not function as intended
Milestone
Describe the bug
If you add a new class name to a block with an existing class and then remove that class it triggers a validation warning even though the content is correct.
To Reproduce
<blockquote>
:<blockquote class="wp-block-quote newclass”><p>fdsfsdfsdd</p></blockquote>
newclass
Expected behavior
I'm not sure if changing the class should trigger a validation error, but I don't think removing the new class should.
Further details
Looking into this deeper the
isValidBlock
code invalidation.js
runs when a block has been edited. When the new class is added the code is passedinnerHTML
:<blockquote class="wp-block-quote newclass”><p>fdsfsdfsdd</p></blockquote>
It saves the block to compare the difference and produces:
<blockquote class="wp-block-quote newclass”><p>fdsfsdfsdd</p></blockquote>
Note that the saved block also (incorrectly?) contains the new class. As the HTML is the same no warning is shown. Although this may be a desirable outcome it seems the result of an accident, and may be the source of the problem.
When you then remove the class the
innerHTML
is passed:<blockquote class="wp-block-quote"><p>fdsfsdfsdd</p></blockquote>
However the saved block content is:
<blockquote class="wp-block-quote newclass”><p>fdsfsdfsdd</p></blockquote>
And so it incorrectly triggers an invalid content warning.
I’m not quite sure what is supposed to happen, and I haven’t tried it with other attributes. I’m investigating further as part of #7604 so will report here more findings.
The text was updated successfully, but these errors were encountered: