Skip to content

Commit dcf927f

Browse files
committed
fix(vdomInterop): handle forwarded vapor slots during render VDOM slot
1 parent c23d635 commit dcf927f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/runtime-vapor/src/componentProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ export function hasAttrFromRawProps(rawProps: RawProps, key: string): boolean {
210210
if (dynamicSources) {
211211
let i = dynamicSources.length
212212
while (i--) {
213-
if (hasOwn(resolveSource(dynamicSources[i]), key)) {
213+
const source = resolveSource(dynamicSources[i])
214+
if (source && hasOwn(source, key)) {
214215
return true
215216
}
216217
}

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ import {
2626
mountComponent,
2727
unmountComponent,
2828
} from './component'
29-
import { type Block, VaporFragment, insert, remove } from './block'
29+
import {
30+
type Block,
31+
VaporFragment,
32+
insert,
33+
isFragment,
34+
isValidBlock,
35+
remove,
36+
} from './block'
3037
import { EMPTY_OBJ, extend, isFunction } from '@vue/shared'
3138
import { type RawProps, rawPropsProxyHandlers } from './componentProps'
3239
import type { RawSlots, VaporSlot } from './componentSlots'
@@ -230,7 +237,24 @@ function renderVDOMSlot(
230237
isFunction(name) ? name() : name,
231238
props,
232239
)
233-
if ((vnode.children as any[]).length) {
240+
let isValidSlotContent
241+
let children = vnode.children as any[]
242+
243+
// TODO add tests
244+
// handle forwarded vapor slot
245+
let vaporSlot
246+
if (children.length === 1 && (vaporSlot = children[0].vs)) {
247+
const block = vaporSlot.slot(props)
248+
isValidSlotContent =
249+
isValidBlock(block) ||
250+
// if block is a vapor fragment with insert, it indicates a forwarded VDOM slot
251+
(isFragment(block) && block.insert)
252+
}
253+
// vnode children
254+
else {
255+
isValidSlotContent = children.length > 0
256+
}
257+
if (isValidSlotContent) {
234258
if (fallbackNodes) {
235259
remove(fallbackNodes, parentNode)
236260
fallbackNodes = undefined

0 commit comments

Comments
 (0)