From 3375687df5e7751d3df69190c99f4ce13b8f1993 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 24 Feb 2020 23:05:35 -0500 Subject: [PATCH] fix(runtime-core): fix slot fallback + slots typing fix #772 --- packages/runtime-core/src/componentSlots.ts | 2 +- packages/runtime-core/src/helpers/renderSlot.ts | 6 +++--- packages/runtime-dom/__tests__/modules/class.spec.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 79c8f9d4317..2958903e152 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -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 diff --git a/packages/runtime-core/src/helpers/renderSlot.ts b/packages/runtime-core/src/helpers/renderSlot.ts index eb16bc02200..186cdfed1eb 100644 --- a/packages/runtime-core/src/helpers/renderSlot.ts +++ b/packages/runtime-core/src/helpers/renderSlot.ts @@ -1,5 +1,5 @@ import { Data } from '../component' -import { Slot } from '../componentSlots' +import { Slots } from '../componentSlots' import { VNodeArrayChildren, openBlock, @@ -11,7 +11,7 @@ import { PatchFlags } from '@vue/shared' import { warn } from '../warning' export function renderSlot( - slots: Record, + slots: Slots, name: string, props: Data = {}, // this is not a user-facing function, so the fallback is always generated by @@ -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 ` + diff --git a/packages/runtime-dom/__tests__/modules/class.spec.ts b/packages/runtime-dom/__tests__/modules/class.spec.ts index c12780859c0..2874cbea561 100644 --- a/packages/runtime-dom/__tests__/modules/class.spec.ts +++ b/packages/runtime-dom/__tests__/modules/class.spec.ts @@ -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] } }) @@ -122,7 +122,7 @@ describe('class', () => { { class: 'staticClass' }, - [this.$slots.default()] + [this.$slots.default!()] ) } })