fix(nuxt): check if default slot is provided before calling it (#4842)

This commit is contained in:
Daniel Roe 2022-05-06 11:52:08 +01:00 committed by GitHub
parent 4079882bd4
commit 750460693e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -175,7 +175,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
// converts `""` to `null` to prevent the attribute from being added as empty (`rel=""`) // converts `""` to `null` to prevent the attribute from being added as empty (`rel=""`)
: firstNonUndefined<string | null>(props.rel, options.externalRelAttribute, href ? DEFAULT_EXTERNAL_REL_ATTRIBUTE : '') || null : firstNonUndefined<string | null>(props.rel, options.externalRelAttribute, href ? DEFAULT_EXTERNAL_REL_ATTRIBUTE : '') || null
return h('a', { href, rel, target }, slots.default()) return h('a', { href, rel, target }, slots.default?.())
} }
} }
}) as unknown as DefineComponent<NuxtLinkProps> }) as unknown as DefineComponent<NuxtLinkProps>

View File

@ -3,7 +3,7 @@ import type { Component } from 'vue'
const Fragment = { const Fragment = {
setup (_props, { slots }) { setup (_props, { slots }) {
return () => slots.default() return () => slots.default?.()
} }
} }

View File

@ -135,7 +135,7 @@ export const Base = defineComponent({
export const Title = defineComponent({ export const Title = defineComponent({
name: 'Title', name: 'Title',
setup: setupForUseMeta((_, { slots }) => { setup: setupForUseMeta((_, { slots }) => {
const title = slots.default()?.[0]?.children || null const title = slots.default?.()?.[0]?.children || null
if (process.dev && title && typeof title !== 'string') { if (process.dev && title && typeof title !== 'string') {
console.error('<Title> can only take a string in its default slot.') console.error('<Title> can only take a string in its default slot.')
} }