File tree 2 files changed +53
-4
lines changed
2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -53,13 +53,15 @@ export default {
53
53
} ,
54
54
55
55
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
+
56
60
if ( this . value ) {
57
- Object . assign ( this . config , {
58
- initialData : this . value
59
- } ) ;
61
+ editorConfig . initialData = this . value ;
60
62
}
61
63
62
- this . editor . create ( this . $el , this . config )
64
+ this . editor . create ( this . $el , editorConfig )
63
65
. then ( editor => {
64
66
// Save the reference to the instance for further use.
65
67
this . instance = editor ;
Original file line number Diff line number Diff line change @@ -190,6 +190,53 @@ describe( 'CKEditor Component', () => {
190
190
done ( ) ;
191
191
} ) ;
192
192
} ) ;
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
+ } ) ;
193
240
} ) ;
194
241
195
242
it ( '#instance should be defined' , done => {
You can’t perform that action at this time.
0 commit comments