]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: warn duplicate plugin installations
authorEvan You <yyx990803@gmail.com>
Tue, 5 Nov 2019 15:49:00 +0000 (10:49 -0500)
committerEvan You <yyx990803@gmail.com>
Tue, 5 Nov 2019 15:49:15 +0000 (10:49 -0500)
packages/runtime-core/__tests__/apiApp.spec.ts
packages/runtime-core/src/apiApp.ts

index c78d9157e9621ae0112e2c664596e5541e9c3dbc..417cb772450facd872a043cdb361ce5f961be119 100644 (file)
@@ -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', () => {
index e431945c78ac27f87b563b498964f8dab078c4a2..7b757240ea2e2b3ac7167b8c272925047b7a9af6 100644 (file)
@@ -79,6 +79,7 @@ export function createAppAPI<HostNode, HostElement>(
 ): () => App<HostElement> {
   return function createApp(): App {
     const context = createAppContext()
+    const installedPlugins = new Set()
 
     let isMounted = false
 
@@ -96,9 +97,13 @@ export function createAppAPI<HostNode, HostElement>(
       },
 
       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(