From: zs Date: Fri, 13 May 2022 01:09:18 +0000 (+0800) Subject: chore: warn when mounting different apps on the same host element (#5573) X-Git-Tag: v3.2.34-beta.1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c07f12541061cf10996f998705d7ad36193aa4f;p=thirdparty%2Fvuejs%2Fcore.git chore: warn when mounting different apps on the same host element (#5573) --- diff --git a/packages/runtime-core/__tests__/apiCreateApp.spec.ts b/packages/runtime-core/__tests__/apiCreateApp.spec.ts index e5e9a5906b..3fb5bb1752 100644 --- a/packages/runtime-core/__tests__/apiCreateApp.spec.ts +++ b/packages/runtime-core/__tests__/apiCreateApp.spec.ts @@ -30,6 +30,11 @@ describe('api: createApp', () => { const root1 = nodeOps.createElement('div') createApp(Comp).mount(root1) expect(serializeInner(root1)).toBe(`0`) + //#5571 mount multiple apps to the same host element + createApp(Comp).mount(root1) + expect( + `There is already an app instance mounted on the host container` + ).toHaveBeenWarned() // mount with props const root2 = nodeOps.createElement('div') diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index 6b2093141b..b0c8a3f2bb 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -284,6 +284,14 @@ export function createAppAPI( isSVG?: boolean ): any { if (!isMounted) { + // #5571 + if (__DEV__ && (rootContainer as any).__vue_app__) { + warn( + `There is already an app instance mounted on the host container.\n` + + ` If you want to mount another app on the same host container,` + + ` you need to unmount the previous app by calling \`app.unmount()\` first.` + ) + } const vnode = createVNode( rootComponent as ConcreteComponent, rootProps