fix(onchange): fire mutation event if there are other changes along with mutation-free nodes

This commit is contained in:
Peter Savchenko 2023-02-17 19:59:03 +02:00
commit 3a653a90c8
No known key found for this signature in database
GPG key ID: E68306B1AB0F727C
2 changed files with 11 additions and 9 deletions

View file

@ -204,8 +204,17 @@ export default class Block extends EventsDispatcher<BlockEvents> {
* Is fired when DOM mutation has been happened
*/
private didMutated = _.debounce((mutationsOrInputEvent: MutationRecord[] | InputEvent = []): void => {
/**
* We won't fire a Block mutation event for nodes that contain 'data-mutation-free' attributes
*
* Update from 2023, Feb 17:
* Changed mutationsOrInputEvent.some() to mutationsOrInputEvent.every()
* since there could be a real mutations same-time with mutation-free changes,
* for example when Block Tune change: block is changing along with FakeCursor (mutation-free) removing
* we should fire 'didMutated' event in that case
*/
const shouldFireUpdate = mutationsOrInputEvent instanceof InputEvent ||
!mutationsOrInputEvent.some(({
!mutationsOrInputEvent.every(({
addedNodes = [],
removedNodes,
}) => {

View file

@ -221,14 +221,7 @@ describe('onChange callback', () => {
.click();
cy.get('[data-cy=editorjs]')
.get('span.cdx-settings-button[data-level=4]')
.click()
/**
* For some reason, the first click fires the mutation of removeFakeCursor only, so we need to click again.
* Reproduced only in Cypress.
*
* @todo debug it later
*/
.get('.ce-settings .ce-popover-item:nth-child(4)')
.click();
cy.get('@onChange').should('be.calledWithMatch', EditorJSApiMock, Cypress.sinon.match({