mirror of https://github.com/vuejs/core.git
chore: use stricter slots type in createSlots
This commit is contained in:
parent
05c7b0d180
commit
cae1aa82cc
|
@ -1,9 +1,12 @@
|
||||||
import { Slot } from '../componentSlots'
|
|
||||||
import { isArray } from '@vue/shared'
|
import { isArray } from '@vue/shared'
|
||||||
|
import { VNode } from '../vnode'
|
||||||
|
|
||||||
|
// #6651 res can be undefined in SSR in string push mode
|
||||||
|
type SSRSlot = (...args: any[]) => VNode[] | undefined
|
||||||
|
|
||||||
interface CompiledSlotDescriptor {
|
interface CompiledSlotDescriptor {
|
||||||
name: string
|
name: string
|
||||||
fn: Slot
|
fn: SSRSlot
|
||||||
key?: string
|
key?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +15,13 @@ interface CompiledSlotDescriptor {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export function createSlots(
|
export function createSlots(
|
||||||
slots: Record<string, Slot>,
|
slots: Record<string, SSRSlot>,
|
||||||
dynamicSlots: (
|
dynamicSlots: (
|
||||||
| CompiledSlotDescriptor
|
| CompiledSlotDescriptor
|
||||||
| CompiledSlotDescriptor[]
|
| CompiledSlotDescriptor[]
|
||||||
| undefined
|
| undefined
|
||||||
)[]
|
)[]
|
||||||
): Record<string, Slot> {
|
): Record<string, SSRSlot> {
|
||||||
for (let i = 0; i < dynamicSlots.length; i++) {
|
for (let i = 0; i < dynamicSlots.length; i++) {
|
||||||
const slot = dynamicSlots[i]
|
const slot = dynamicSlots[i]
|
||||||
// array of dynamic slot generated by <template v-for="..." #[...]>
|
// array of dynamic slot generated by <template v-for="..." #[...]>
|
||||||
|
@ -33,7 +36,6 @@ export function createSlots(
|
||||||
const res = slot.fn(...args)
|
const res = slot.fn(...args)
|
||||||
// attach branch key so each conditional branch is considered a
|
// attach branch key so each conditional branch is considered a
|
||||||
// different fragment
|
// different fragment
|
||||||
// #6651 res can be undefined in SSR in string push mode
|
|
||||||
if (res) (res as any).key = slot.key
|
if (res) (res as any).key = slot.key
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue