]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: warn when mounting different apps on the same host element (#5573)
authorzs <zscumt123@163.com>
Fri, 13 May 2022 01:09:18 +0000 (09:09 +0800)
committerGitHub <noreply@github.com>
Fri, 13 May 2022 01:09:18 +0000 (21:09 -0400)
packages/runtime-core/__tests__/apiCreateApp.spec.ts
packages/runtime-core/src/apiCreateApp.ts

index e5e9a5906b1ce5fa167e827267bdb34f48c4cb4e..3fb5bb17529aa194ef33460f5c9a44c70a25cf0c 100644 (file)
@@ -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')
index 6b2093141bdd906b18937b27b38b8e58c7d5a0ff..b0c8a3f2bba2771c3dbdd0555f5159cb8ca64b50 100644 (file)
@@ -284,6 +284,14 @@ export function createAppAPI<HostElement>(
         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