diff --git a/packages/runtime-core/__tests__/apiApp.spec.ts b/packages/runtime-core/__tests__/apiApp.spec.ts index c78d9157..417cb772 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 e431945c..7b757240 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(