Skip to content

Commit f1d10dc

Browse files
committed
fix: reactive props and keep refs
1 parent 0fba4d1 commit f1d10dc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/mount.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
h,
33
createApp,
44
defineComponent,
5+
reactive,
56
shallowReactive,
7+
isRef,
68
FunctionalComponent,
79
ComponentPublicInstance,
810
ComponentOptionsWithObjectProps,
@@ -379,12 +381,22 @@ export function mount(
379381
const MOUNT_COMPONENT_REF = 'VTU_COMPONENT'
380382
// we define props as reactive so that way when we update them with `setProps`
381383
// Vue's reactivity system will cause a rerender.
382-
const props = shallowReactive({
384+
const refs = shallowReactive<Record<string, unknown>>({})
385+
const props = reactive<Record<string, unknown>>({})
386+
387+
Object.entries({
383388
...options?.attrs,
384389
...options?.propsData,
385390
...options?.props,
386391
ref: MOUNT_COMPONENT_REF
392+
}).forEach(([k, v]) => {
393+
if (isRef(v)) {
394+
refs[k] = v
395+
} else {
396+
props[k] = v
397+
}
387398
})
399+
388400
const global = mergeGlobalProperties(options?.global)
389401
if (isObjectComponent(component)) {
390402
component.components = { ...component.components, ...global.components }
@@ -394,7 +406,7 @@ export function mount(
394406
const Parent = defineComponent({
395407
name: 'VTU_ROOT',
396408
render() {
397-
return h(component, props, slots)
409+
return h(component as ComponentOptions, { ...props, ...refs }, slots)
398410
}
399411
})
400412

0 commit comments

Comments
 (0)