diff --git a/packages/rich-text/src/test/to-dom.js b/packages/rich-text/src/test/to-dom.js index 8db8a52e1b4435..2036ba24b80f7a 100644 --- a/packages/rich-text/src/test/to-dom.js +++ b/packages/rich-text/src/test/to-dom.js @@ -59,6 +59,42 @@ describe( 'applyValue', () => { movedCount: 0, description: 'should not modify', }, + { + current: 'b', + future: 'b', + movedCount: 0, + description: 'should remove attribute', + }, + { + current: 'b', + future: 'b', + movedCount: 0, + description: 'should remove attributes', + }, + { + current: 'a', + future: 'c', + movedCount: 0, + description: 'should add attribute', + }, + { + current: 'a', + future: 'c', + movedCount: 0, + description: 'should add attributes', + }, + { + current: 'a', + future: 'a', + movedCount: 0, + description: 'should update attribute', + }, + { + current: 'a', + future: 'a', + movedCount: 0, + description: 'should update attributes', + }, ]; cases.forEach( ( { current, future, description, movedCount } ) => { diff --git a/packages/rich-text/src/to-dom.js b/packages/rich-text/src/to-dom.js index e56711fe13a4e5..d99cdd055feda0 100644 --- a/packages/rich-text/src/to-dom.js +++ b/packages/rich-text/src/to-dom.js @@ -207,7 +207,11 @@ export function applyValue( future, current ) { const futureAttributes = futureChild.attributes; if ( currentAttributes ) { - for ( let ii = 0; ii < currentAttributes.length; ii++ ) { + let ii = currentAttributes.length; + + // Reverse loop because `removeAttribute` on `currentChild` + // changes `currentAttributes`. + while ( ii-- ) { const { name } = currentAttributes[ ii ]; if ( ! futureChild.getAttribute( name ) ) {