KSES filters force a dirty state in the editor
Describe the bug
As of Gutenberg 6.4.0, the KSES filters are making the editor to believe there are unsaved changes where there are none.
These filters are only registered when a user doesn't have the unfiltered_html capability (which is the case for multisite regular admins).
When these filters are active, syntax like <img src="..." class="..."/> (produced by the core/image block) is transformed to <img src="..." class="..." /> (note the extra whitespace at the end).
That extra whitespace is putting the editor in dirty state, but it seems that those whitespaces were ignored on Gutenberg 6.3.0 and below.
To reproduce
-
Activate Gutenberg 6.4.0 on a multisite install, or test with a user not having the
unfiltered_htmlcapability. -
Add a new post and insert an image block.
-
Publish the post.
-
Note how the publish sidebar is automatically hidden.
-
Note how the "Update" button is enabled, despite not having entered any change.
-
Run
wp.data.select('core/editor').getEditedPostAttribute('content')andwp.data.select('core/editor').getCurrentPostAttribute('content')on the browser devtools console. -
Note how the current post content contains an extra whitespace:

-
Run
wp.data.select('core/editor').isEditedPostDirty()on the browser devtools console. -
Note how the above command returns
true.
Expected behavior The same behavior we had in Gutenberg 6.3.0 and below:
- The publish sidebar shouldn't disappear in 4.
- The "Update" button should be disabled in 5.
isEditedPostDirtyshould return false in 8.
Related: #15137.
Maybe related: #17491
This is no longer reproducible, probably solved by https://github.com/WordPress/gutenberg/pull/17532