Skip to content

Commit 1380114

Browse files
committed
fix: add helpers for class/object/functional component to ensure correct mounting strategy
1 parent f4c20bf commit 1380114

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/mount.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ import {
2626

2727
import { config } from './config'
2828
import { GlobalMountOptions } from './types'
29-
import { isClassComponent, mergeGlobalProperties } from './utils'
29+
import {
30+
isClassComponent,
31+
isFunctionalComponent,
32+
isObjectComponent,
33+
mergeGlobalProperties
34+
} from './utils'
3035
import { processSlot } from './utils/compileSlots'
3136
import { createWrapper, VueWrapper } from './vueWrapper'
3237
import { attachEmitListener } from './emitMixin'
@@ -231,11 +236,11 @@ export function mount(
231236
options?: MountingOptions<any>
232237
): VueWrapper<any> {
233238
// normalise the incoming component
234-
let component = originalComponent
239+
let component
235240

236241
const functionalComponentEmits: Record<string, unknown[]> = {}
237242

238-
if (typeof originalComponent === 'function' && !isClassComponent(component)) {
243+
if (isFunctionalComponent(originalComponent)) {
239244
// we need to wrap it like this so we can capture emitted events.
240245
// we capture events using a mixin that mutates `emit` in `beforeCreate`,
241246
// but functional components do not support mixins, so we need to wrap it
@@ -247,6 +252,10 @@ export function mount(
247252
)
248253
}
249254
})
255+
} else if (isObjectComponent(originalComponent)) {
256+
component = { ...originalComponent }
257+
} else {
258+
component = originalComponent
250259
}
251260

252261
const el = document.createElement('div')

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ export const mergeDeep = (
6868
export function isClassComponent(component: any) {
6969
return '__vccBase' in component
7070
}
71+
72+
export function isFunctionalComponent(component: any) {
73+
return typeof component === 'function' && !isClassComponent(component)
74+
}
75+
76+
export function isObjectComponent(component: any) {
77+
return typeof component !== 'function' && !isClassComponent(component)
78+
}

0 commit comments

Comments
 (0)