Skip to content

Commit 0c07f12

Browse files
authored
chore: warn when mounting different apps on the same host element (#5573)
1 parent f2c48f5 commit 0c07f12

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/runtime-core/__tests__/apiCreateApp.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ describe('api: createApp', () => {
3030
const root1 = nodeOps.createElement('div')
3131
createApp(Comp).mount(root1)
3232
expect(serializeInner(root1)).toBe(`0`)
33+
//#5571 mount multiple apps to the same host element
34+
createApp(Comp).mount(root1)
35+
expect(
36+
`There is already an app instance mounted on the host container`
37+
).toHaveBeenWarned()
3338

3439
// mount with props
3540
const root2 = nodeOps.createElement('div')

packages/runtime-core/src/apiCreateApp.ts

+8
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ export function createAppAPI<HostElement>(
284284
isSVG?: boolean
285285
): any {
286286
if (!isMounted) {
287+
// #5571
288+
if (__DEV__ && (rootContainer as any).__vue_app__) {
289+
warn(
290+
`There is already an app instance mounted on the host container.\n` +
291+
` If you want to mount another app on the same host container,` +
292+
` you need to unmount the previous app by calling \`app.unmount()\` first.`
293+
)
294+
}
287295
const vnode = createVNode(
288296
rootComponent as ConcreteComponent,
289297
rootProps

0 commit comments

Comments
 (0)