Skip to content

Commit 4a5b91b

Browse files
committed
fix(runtime-core): fix slot fallback + slots typing
fix #773
1 parent 19a799c commit 4a5b91b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packages/runtime-core/src/componentSlots.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isKeepAlive } from './components/KeepAlive'
1212
export type Slot = (...args: any[]) => VNode[]
1313

1414
export type InternalSlots = {
15-
[name: string]: Slot
15+
[name: string]: Slot | undefined
1616
}
1717

1818
export type Slots = Readonly<InternalSlots>

packages/runtime-core/src/helpers/renderSlot.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Data } from '../component'
2-
import { Slot } from '../componentSlots'
2+
import { Slots } from '../componentSlots'
33
import {
44
VNodeArrayChildren,
55
openBlock,
@@ -11,7 +11,7 @@ import { PatchFlags } from '@vue/shared'
1111
import { warn } from '../warning'
1212

1313
export function renderSlot(
14-
slots: Record<string, Slot>,
14+
slots: Slots,
1515
name: string,
1616
props: Data = {},
1717
// this is not a user-facing function, so the fallback is always generated by
@@ -20,7 +20,7 @@ export function renderSlot(
2020
): VNode {
2121
let slot = slots[name]
2222

23-
if (__DEV__ && slot.length > 1) {
23+
if (__DEV__ && slot && slot.length > 1) {
2424
warn(
2525
`SSR-optimized slot function detected in a non-SSR-optimized render ` +
2626
`function. You need to mark this component with $dynamic-slots in the ` +

packages/runtime-dom/__tests__/modules/class.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ describe('class', () => {
103103
const component1 = defineComponent({
104104
props: {},
105105
render() {
106-
return this.$slots.default()[0]
106+
return this.$slots.default!()[0]
107107
}
108108
})
109109

110110
const component2 = defineComponent({
111111
props: {},
112112
render() {
113-
return this.$slots.default()[0]
113+
return this.$slots.default!()[0]
114114
}
115115
})
116116

@@ -122,7 +122,7 @@ describe('class', () => {
122122
{
123123
class: 'staticClass'
124124
},
125-
[this.$slots.default()]
125+
[this.$slots.default!()]
126126
)
127127
}
128128
})

0 commit comments

Comments
 (0)