export type Slot = (...args: any[]) => VNode[]
export type InternalSlots = {
- [name: string]: Slot
+ [name: string]: Slot | undefined
}
export type Slots = Readonly<InternalSlots>
import { Data } from '../component'
-import { Slot } from '../componentSlots'
+import { Slots } from '../componentSlots'
import {
VNodeArrayChildren,
openBlock,
import { warn } from '../warning'
export function renderSlot(
- slots: Record<string, Slot>,
+ slots: Slots,
name: string,
props: Data = {},
// this is not a user-facing function, so the fallback is always generated by
): VNode {
let slot = slots[name]
- if (__DEV__ && slot.length > 1) {
+ if (__DEV__ && slot && 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 ` +
const component1 = defineComponent({
props: {},
render() {
- return this.$slots.default()[0]
+ return this.$slots.default!()[0]
}
})
const component2 = defineComponent({
props: {},
render() {
- return this.$slots.default()[0]
+ return this.$slots.default!()[0]
}
})
{
class: 'staticClass'
},
- [this.$slots.default()]
+ [this.$slots.default!()]
)
}
})