瀏覽代碼

Merge pull request #215 from ckeditor/i/6219

Internal: Introduced copying builtin plugins to get rid of shared references between editors[ (because of the watchdog). Part of ckeditor/ckeditor5#6219.
Piotrek Koszuliński 6 年之前
父節點
當前提交
104d0102e7
共有 2 個文件被更改,包括 21 次插入3 次删除
  1. 4 2
      packages/ckeditor5-core/src/editor/editor.js
  2. 17 1
      packages/ckeditor5-core/tests/editor/editor.js

+ 4 - 2
packages/ckeditor5-core/src/editor/editor.js

@@ -61,7 +61,9 @@ export default class Editor {
 		this._context = config.context || new Context( { language: config.language } );
 		this._context._addEditor( this, !config.context );
 
-		const availablePlugins = this.constructor.builtinPlugins;
+		// Clone the plugins to make sure that the plugin array will not be shared
+		// between editors and make the watchdog feature work correctly.
+		const availablePlugins = Array.from( this.constructor.builtinPlugins || [] );
 
 		/**
 		 * Stores all configurations specific to this editor instance.
@@ -227,7 +229,7 @@ export default class Editor {
 	 */
 	initPlugins() {
 		const config = this.config;
-		const plugins = config.get( 'plugins' ) || [];
+		const plugins = config.get( 'plugins' );
 		const removePlugins = config.get( 'removePlugins' ) || [];
 		const extraPlugins = config.get( 'extraPlugins' ) || [];
 

+ 17 - 1
packages/ckeditor5-core/tests/editor/editor.js

@@ -262,7 +262,23 @@ describe( 'Editor', () => {
 			const context = await Context.create( { plugins: [ ContextPlugin ] } );
 			const editor = await TestEditor.create( { context } );
 
-			expect( editor.config.get( 'plugins' ) ).to.be.undefined;
+			expect( editor.config.get( 'plugins' ) ).to.be.empty;
+		} );
+
+		it( 'should copy builtin plugins', async () => {
+			TestEditor.builtinPlugins = [ PluginA ];
+
+			class ContextPlugin {
+				static get isContextPlugin() {
+					return true;
+				}
+			}
+
+			const context = await Context.create( { plugins: [ ContextPlugin ] } );
+			const editor = await TestEditor.create( { context } );
+
+			expect( editor.config.get( 'plugins' ) ).to.deep.equal( [ PluginA ] );
+			expect( editor.config.get( 'plugins' ) ).to.not.equal( TestEditor.builtinPlugins );
 		} );
 
 		it( 'should pass DOM element using reference, not copy', async () => {