-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
renderSlot.ts
41 lines (38 loc) · 984 Bytes
/
renderSlot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Data } from '../component'
import { Slot } from '../componentSlots'
import {
VNodeArrayChildren,
openBlock,
createBlock,
Fragment,
VNode
} from '../vnode'
import { PatchFlags } from '@vue/shared'
import { warn } from '../warning'
export function renderSlot(
slots: Record<string, Slot>,
name: string,
props: Data = {},
// this is not a user-facing function, so the fallback is always generated by
// the compiler and guaranteed to be an array
fallback?: VNodeArrayChildren
): VNode {
let slot = slots[name]
if (__DEV__ && slot.length > 1) {
warn(
`SSR-optimized slot function detected in a non-SSR-optimized render ` +
`function. You need to mark this component with $dynamic-slots in the ` +
`parent template.`
)
slot = () => []
}
return (
openBlock(),
createBlock(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || [],
slots._ ? 0 : PatchFlags.BAIL
)
)
}