Skip to content

Commit

Permalink
fix(runtime-core): fix slot fallback + slots typing
Browse files Browse the repository at this point in the history
fix #772
  • Loading branch information
yyx990803 committed Feb 25, 2020
1 parent 19a799c commit 3375687
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { isKeepAlive } from './components/KeepAlive'
export type Slot = (...args: any[]) => VNode[]

export type InternalSlots = {
[name: string]: Slot
[name: string]: Slot | undefined
}

export type Slots = Readonly<InternalSlots>
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data } from '../component'
import { Slot } from '../componentSlots'
import { Slots } from '../componentSlots'
import {
VNodeArrayChildren,
openBlock,
Expand All @@ -11,7 +11,7 @@ import { PatchFlags } from '@vue/shared'
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
Expand All @@ -20,7 +20,7 @@ export function renderSlot(
): 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 ` +
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-dom/__tests__/modules/class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ describe('class', () => {
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]
}
})

Expand All @@ -122,7 +122,7 @@ describe('class', () => {
{
class: 'staticClass'
},
[this.$slots.default()]
[this.$slots.default!()]
)
}
})
Expand Down

0 comments on commit 3375687

Please sign in to comment.