Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

External modifications of the editing root should not crash the editor #220

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils/injecttypingmutationshandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class MutationHandler {
// This situation happens for example for lists. If `<ul>` is a common ancestor, `currentModel` is `undefined`
// because `<ul>` is not mapped (`<li>`s are).
// See https://github.com/ckeditor/ckeditor5/issues/718.
if ( !currentModel ) {
// Also, if a current DOM was cleared (happened with VUE integration - it is also safe to return early here.
// See https://github.com/ckeditor/ckeditor5/issues/2016.
if ( !currentModel || !modelFromCurrentDom ) {
return;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,32 @@ describe( 'Input feature', () => {

expect( getViewData( view ) ).to.equal( '<p>Foox{}<strong> </strong> Bar</p>' );
} );

// https://github.com/ckeditor/ckeditor5/issues/2016
it( 'should not crash on external modifications to the editing DOM root', done => {
editor.setData( '<p>Foo</p>' );

model.document.on( 'change:data', () => {
const domRoot = editor.editing.view.getDomRoot( 'main' );
domRoot.removeChild( domRoot.children[ 0 ] );

const p = viewRoot.getChild( 0 );

viewDocument.fire( 'mutations', [
{
type: 'children',
oldChildren: [ p ],
newChildren: [],
node: viewRoot
}
] );

done();
} );

const paragraph = model.document.getRoot().getChild( 0 );
model.deleteContent( model.createSelection( paragraph, 'in' ) );
} );
} );

describe( 'keystroke handling', () => {
Expand Down