From: Evan You Date: Tue, 5 Nov 2019 15:49:00 +0000 (-0500) Subject: feat: warn duplicate plugin installations X-Git-Tag: v3.0.0-alpha.0~237 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c61e5463fa77a56c4271db958e4a8e48bb2ae233;p=thirdparty%2Fvuejs%2Fcore.git feat: warn duplicate plugin installations --- diff --git a/packages/runtime-core/__tests__/apiApp.spec.ts b/packages/runtime-core/__tests__/apiApp.spec.ts index c78d9157e9..417cb77245 100644 --- a/packages/runtime-core/__tests__/apiApp.spec.ts +++ b/packages/runtime-core/__tests__/apiApp.spec.ts @@ -259,6 +259,11 @@ describe('api: createApp', () => { const root = nodeOps.createElement('div') app.mount(Root, root) expect(serializeInner(root)).toBe(`1,2`) + + app.use(PluginA) + expect( + `Plugin has already been applied to target app` + ).toHaveBeenWarnedTimes(1) }) test('config.errorHandler', () => { diff --git a/packages/runtime-core/src/apiApp.ts b/packages/runtime-core/src/apiApp.ts index e431945c78..7b757240ea 100644 --- a/packages/runtime-core/src/apiApp.ts +++ b/packages/runtime-core/src/apiApp.ts @@ -79,6 +79,7 @@ export function createAppAPI( ): () => App { return function createApp(): App { const context = createAppContext() + const installedPlugins = new Set() let isMounted = false @@ -96,9 +97,13 @@ export function createAppAPI( }, use(plugin: Plugin) { - if (isFunction(plugin)) { + if (installedPlugins.has(plugin)) { + __DEV__ && warn(`Plugin has already been applied to target app.`) + } else if (isFunction(plugin)) { + installedPlugins.add(plugin) plugin(app) } else if (isFunction(plugin.install)) { + installedPlugins.add(plugin) plugin.install(app) } else if (__DEV__) { warn(