Skip to content

Commit 2696f14

Browse files
committed
wip(vapor): fix insertion for vdom interop
1 parent e5e4d29 commit 2696f14

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

packages/runtime-vapor/src/component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ export function createComponent(
146146

147147
// vdom interop enabled and component is not an explicit vapor component
148148
if (appContext.vapor && !component.__vapor) {
149-
return appContext.vapor.vdomMount(component as any, rawProps, rawSlots)
149+
const frag = appContext.vapor.vdomMount(
150+
component as any,
151+
rawProps,
152+
rawSlots,
153+
)
154+
if (!isHydrating && _insertionParent) {
155+
insert(frag, _insertionParent, _insertionAnchor)
156+
}
157+
return frag
150158
}
151159

152160
if (

packages/runtime-vapor/src/componentSlots.ts

+29-27
Original file line numberDiff line numberDiff line change
@@ -104,45 +104,47 @@ export function createSlot(
104104
? new Proxy(rawProps, rawPropsProxyHandlers)
105105
: EMPTY_OBJ
106106

107+
let fragment: DynamicFragment
108+
107109
if (isRef(rawSlots._)) {
108-
return instance.appContext.vapor!.vdomSlot(
110+
fragment = instance.appContext.vapor!.vdomSlot(
109111
rawSlots._,
110112
name,
111113
slotProps,
112114
instance,
113115
fallback,
114116
)
115-
}
117+
} else {
118+
fragment = __DEV__ ? new DynamicFragment('slot') : new DynamicFragment()
119+
const isDynamicName = isFunction(name)
120+
const renderSlot = () => {
121+
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
122+
if (slot) {
123+
// create and cache bound version of the slot to make it stable
124+
// so that we avoid unnecessary updates if it resolves to the same slot
125+
fragment.update(
126+
slot._bound ||
127+
(slot._bound = () => {
128+
const slotContent = slot(slotProps)
129+
if (slotContent instanceof DynamicFragment) {
130+
slotContent.fallback = fallback
131+
}
132+
return slotContent
133+
}),
134+
)
135+
} else {
136+
fragment.update(fallback)
137+
}
138+
}
116139

117-
const isDynamicName = isFunction(name)
118-
const fragment = __DEV__ ? new DynamicFragment('slot') : new DynamicFragment()
119-
const renderSlot = () => {
120-
const slot = getSlot(rawSlots, isFunction(name) ? name() : name)
121-
if (slot) {
122-
// create and cache bound version of the slot to make it stable
123-
// so that we avoid unnecessary updates if it resolves to the same slot
124-
fragment.update(
125-
slot._bound ||
126-
(slot._bound = () => {
127-
const slotContent = slot(slotProps)
128-
if (slotContent instanceof DynamicFragment) {
129-
slotContent.fallback = fallback
130-
}
131-
return slotContent
132-
}),
133-
)
140+
// dynamic slot name or has dynamicSlots
141+
if (isDynamicName || rawSlots.$) {
142+
renderEffect(renderSlot)
134143
} else {
135-
fragment.update(fallback)
144+
renderSlot()
136145
}
137146
}
138147

139-
// dynamic slot name or has dynamicSlots
140-
if (isDynamicName || rawSlots.$) {
141-
renderEffect(renderSlot)
142-
} else {
143-
renderSlot()
144-
}
145-
146148
if (!isHydrating && _insertionParent) {
147149
insert(fragment, _insertionParent, _insertionAnchor)
148150
}

0 commit comments

Comments
 (0)