]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix slot fallback + slots typing
authorEvan You <yyx990803@gmail.com>
Tue, 25 Feb 2020 04:05:35 +0000 (23:05 -0500)
committerEvan You <yyx990803@gmail.com>
Tue, 25 Feb 2020 14:41:07 +0000 (09:41 -0500)
fix #773

packages/runtime-core/src/componentSlots.ts
packages/runtime-core/src/helpers/renderSlot.ts
packages/runtime-dom/__tests__/modules/class.spec.ts

index 79c8f9d43174178bfa72edc02ca1711c92979efc..2958903e1527c66eeb48250a16d3b7a36120e54e 100644 (file)
@@ -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>
index eb16bc02200a3e28789feeabe21e5392250e032e..186cdfed1ebb1211e31f574b771025b043651a06 100644 (file)
@@ -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<string, Slot>,
+  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 ` +
index c12780859c0eafec9da9f5a7c2f9e9eccbb5265c..2874cbea561913240ade77faf569e1ba1666aa8c 100644 (file)
@@ -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!()]
         )
       }
     })