Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nuxt): improve warning for invalid children of <Title> #21613

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/nuxt/src/head/runtime/components.ts
Expand Up @@ -149,12 +149,20 @@ export const Title = defineComponent({
name: 'Title',
inheritAttrs: false,
setup: setupForUseMeta((_, { slots }) => {
const title = slots.default?.()?.[0]?.children || null
if (process.dev && title && typeof title !== 'string') {
console.error('<Title> can only take a string in its default slot.')
if (process.dev) {
const defaultSlot = slots.default?.()

if (defaultSlot && (defaultSlot.length > 1 || typeof defaultSlot[0].children !== 'string')) {
console.error('<Title> can take only one string in its default slot.')
}

return {
title: defaultSlot?.[0]?.children || null
}
}

return {
title
title: slots.default?.()?.[0]?.children || null
}
})
})
Expand Down