Skip to content

Commit 42651e3

Browse files
authored
Merge pull request #103 from ckeditor/i/101
Fix: Editor config defined in the component should not be mutable. Closes #101.
2 parents 0a41e75 + 609aea2 commit 42651e3

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

Diff for: src/ckeditor.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ export default {
5353
},
5454

5555
mounted() {
56+
// Clone the config first so it never gets mutated (across multiple editor instances).
57+
// https://github.com/ckeditor/ckeditor5-vue/issues/101
58+
const editorConfig = Object.assign( {}, this.config );
59+
5660
if ( this.value ) {
57-
Object.assign( this.config, {
58-
initialData: this.value
59-
} );
61+
editorConfig.initialData = this.value;
6062
}
6163

62-
this.editor.create( this.$el, this.config )
64+
this.editor.create( this.$el, editorConfig )
6365
.then( editor => {
6466
// Save the reference to the instance for further use.
6567
this.instance = editor;

Diff for: tests/ckeditor.js

+47
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,53 @@ describe( 'CKEditor Component', () => {
190190
done();
191191
} );
192192
} );
193+
194+
// https://github.com/ckeditor/ckeditor5-vue/issues/101
195+
it( 'should not be mutated', done => {
196+
const createStub = sandbox.stub( MockEditor, 'create' ).resolves( new MockEditor() );
197+
198+
const ParentComponent = {
199+
data() {
200+
return {
201+
editor: MockEditor,
202+
editorConfig: {
203+
foo: 'bar'
204+
},
205+
editorFooData: 'foo',
206+
editorBarData: 'bar',
207+
editorBazData: 'baz'
208+
};
209+
},
210+
template: `
211+
<div>
212+
<ckeditor :editor="editor" tag-name="textarea" v-model="editorFooData" :config="editorConfig">foo</ckeditor>
213+
<ckeditor :editor="editor" tag-name="textarea" v-model="editorBarData" :config="editorConfig">bar</ckeditor>
214+
<ckeditor :editor="editor" tag-name="textarea" v-model="editorBazData" :config="editorConfig">baz</ckeditor>
215+
</div>
216+
`
217+
};
218+
219+
const { vm } = mount( ParentComponent, {
220+
stubs: {
221+
ckeditor: CKEditorComponent
222+
}
223+
} );
224+
225+
Vue.nextTick( () => {
226+
const fooEditorConfig = createStub.firstCall.args[ 1 ];
227+
const barEditorConfig = createStub.secondCall.args[ 1 ];
228+
const bazEditorConfig = createStub.thirdCall.args[ 1 ];
229+
230+
expect( fooEditorConfig ).to.not.equal( barEditorConfig );
231+
expect( fooEditorConfig ).to.not.equal( bazEditorConfig );
232+
expect( barEditorConfig ).to.not.equal( bazEditorConfig );
233+
234+
expect( vm.editorConfig.initialData ).to.be.undefined;
235+
236+
wrapper.destroy();
237+
done();
238+
} );
239+
} );
193240
} );
194241

195242
it( '#instance should be defined', done => {

0 commit comments

Comments
 (0)