chore: warn when mounting different apps on the same host element (#5573)
This commit is contained in:
parent
f2c48f5352
commit
0c07f12541
@ -30,6 +30,11 @@ describe('api: createApp', () => {
|
|||||||
const root1 = nodeOps.createElement('div')
|
const root1 = nodeOps.createElement('div')
|
||||||
createApp(Comp).mount(root1)
|
createApp(Comp).mount(root1)
|
||||||
expect(serializeInner(root1)).toBe(`0`)
|
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
|
// mount with props
|
||||||
const root2 = nodeOps.createElement('div')
|
const root2 = nodeOps.createElement('div')
|
||||||
|
@ -284,6 +284,14 @@ export function createAppAPI<HostElement>(
|
|||||||
isSVG?: boolean
|
isSVG?: boolean
|
||||||
): any {
|
): any {
|
||||||
if (!isMounted) {
|
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(
|
const vnode = createVNode(
|
||||||
rootComponent as ConcreteComponent,
|
rootComponent as ConcreteComponent,
|
||||||
rootProps
|
rootProps
|
||||||
|
Loading…
Reference in New Issue
Block a user