Skip to content

Commit 6f821fa

Browse files
authored
Merge pull request #48 from ckeditor/t/47
Fix: The data initialization should not break collaboration. Instead of using `editor.setData()`, the initial content is now set via `innerHTML` of the source element. Closes #47.
2 parents 14be583 + 9c9a6ec commit 6f821fa

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

Diff for: src/ckeditor.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export default {
1313
name: 'ckeditor',
1414

1515
render( createElement ) {
16-
return createElement( this.tagName );
16+
return createElement( this.tagName, {
17+
domProps: {
18+
innerHTML: this.value || ''
19+
}
20+
} );
1721
},
1822

1923
props: {
@@ -58,9 +62,6 @@ export default {
5862
// Save the reference to the instance for further use.
5963
this.instance = editor;
6064

61-
// Set the initial data of the editor.
62-
editor.setData( this.value );
63-
6465
// Set initial disabled state.
6566
editor.isReadOnly = this.disabled;
6667

Diff for: tests/_utils/mockeditor.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ export class ModelDocument {
77
on() {}
88
}
99

10-
export class ViewlDocument {
10+
export class ViewDocument {
1111
on() {}
1212
}
1313

14-
export default class MockEditor {
14+
export class MockEditor {
1515
constructor( el, config ) {
1616
this.element = el;
1717
this.config = config;
1818
this.data = '';
19+
this.setDataCounter = 0;
1920

2021
this.model = {
2122
document: new ModelDocument()
2223
};
2324

2425
this.editing = {
2526
view: {
26-
document: new ViewlDocument()
27+
document: new ViewDocument()
2728
}
2829
};
2930
}
@@ -39,6 +40,7 @@ export default class MockEditor {
3940
}
4041

4142
setData( data ) {
43+
this.setDataCounter++;
4244
this.data = data;
4345
}
4446

Diff for: tests/ckeditor.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
import Vue from 'vue';
99
import { mount } from '@vue/test-utils';
1010
import CKEditorComponent from '../src/ckeditor';
11-
import MockEditor from './_utils/mockeditor';
12-
import { ModelDocument, ViewlDocument } from './_utils/mockeditor';
11+
import {
12+
MockEditor,
13+
ModelDocument,
14+
ViewDocument
15+
} from './_utils/mockeditor';
1316

1417
describe( 'CKEditor Component', () => {
1518
let sandbox, wrapper, vm;
@@ -69,7 +72,8 @@ describe( 'CKEditor Component', () => {
6972
const { wrapper } = createComponent();
7073

7174
setTimeout( () => {
72-
consoleErrorStub.restore()
75+
consoleErrorStub.restore();
76+
7377
expect( consoleErrorStub.calledOnce ).to.be.true;
7478
expect( consoleErrorStub.firstCall.args[ 0 ] ).to.equal( error );
7579

@@ -114,16 +118,17 @@ describe( 'CKEditor Component', () => {
114118
expect( vm.value ).to.equal( '' );
115119
} );
116120

121+
// See: https://github.com/ckeditor/ckeditor5-vue/issues/47.
117122
it( 'should set the initial data', done => {
118123
Vue.config.errorHandler = done;
119124

120-
const setDataStub = sandbox.stub( MockEditor.prototype, 'setData' );
121-
const { wrapper } = createComponent( {
125+
const { wrapper, vm } = createComponent( {
122126
value: 'foo'
123127
} );
124128

125129
Vue.nextTick( () => {
126-
sinon.assert.calledWithExactly( setDataStub, 'foo' );
130+
expect( vm.$el.innerHTML ).to.equal( 'foo' );
131+
expect( vm.instance.setDataCounter ).to.equal( 0 );
127132

128133
wrapper.destroy();
129134
done();
@@ -304,7 +309,7 @@ describe( 'CKEditor Component', () => {
304309
it( 'emits #focus when editor editable is focused', done => {
305310
Vue.config.errorHandler = done;
306311

307-
sandbox.stub( ViewlDocument.prototype, 'on' );
312+
sandbox.stub( ViewDocument.prototype, 'on' );
308313

309314
Vue.nextTick( () => {
310315
const on = vm.instance.editing.view.document.on;
@@ -330,7 +335,7 @@ describe( 'CKEditor Component', () => {
330335
it( 'emits #blur when editor editable is focused', done => {
331336
Vue.config.errorHandler = done;
332337

333-
sandbox.stub( ViewlDocument.prototype, 'on' );
338+
sandbox.stub( ViewDocument.prototype, 'on' );
334339

335340
Vue.nextTick( () => {
336341
const on = vm.instance.editing.view.document.on;

Diff for: tests/plugin/localcomponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Vue from 'vue';
77
import { mount } from '@vue/test-utils';
88
import CKEditor from '../../src/plugin';
9-
import MockEditor from '../_utils/mockeditor';
9+
import { MockEditor } from '../_utils/mockeditor';
1010

1111
class FooEditor extends MockEditor {}
1212
class BarEditor extends MockEditor {}

0 commit comments

Comments
 (0)