Skip to content

Commit

Permalink
Fix removing attributes from DOM element.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmotyczynska committed Nov 19, 2024
1 parent 31ed45a commit 94a2e14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ckeditor5-engine/src/view/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,9 @@ export default class Renderer extends /* #__PURE__ */ ObservableMixin() {
// Note: It is important to first remove DOM attributes and then set new ones, because some view attributes may be renamed
// as they are set on DOM (due to unsafe attributes handling). If we set the view attribute first, and then remove
// non-existing DOM attributes, then we would remove the attribute that we just set.
for ( const domAttr of ( domElement as DomElement ).attributes ) {
//
// Note: The domElement.attributes is a live collection, so we need to convert it to an array to avoid issues.
for ( const domAttr of Array.from( ( domElement as DomElement ).attributes ) ) {
const key = domAttr.name;

// All other attributes not present in the DOM should be removed.
Expand Down
13 changes: 13 additions & 0 deletions packages/ckeditor5-engine/tests/view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ describe( 'Renderer', () => {
expect( renderer.markedAttributes.size ).to.equal( 0 );
} );

it( 'should remove all attributes', () => {
domRoot.setAttribute( 'style', 'border:1px solid red' );
domRoot.setAttribute( 'class', 'bar' );

renderer.markToSync( 'attributes', viewRoot );
renderer.render();

expect( domRoot.getAttribute( 'class' ) ).to.be.not.ok;
expect( domRoot.getAttribute( 'style' ) ).to.be.not.ok;

expect( renderer.markedAttributes.size ).to.equal( 0 );
} );

it( 'should add children', () => {
viewRoot._appendChild( new ViewText( viewDocument, 'foo' ) );

Expand Down

0 comments on commit 94a2e14

Please sign in to comment.