title
in useHead
composable, when a function/computed, should be allowed to return undefined
#435
Labels
bug
Something isn't working
Environment
Reproduction
https://stackblitz.com/edit/vitejs-vite-qt6hy722
Describe the bug
useHead
/useSeoMeta
'stitle
supports passing a function or a Vue composable. As the types suggest, the return type should bestring | null
.However, if
undefined
is returned, the behavior differs from returning an empty string ornull
, and is desirable in my case. I have a componentA
, which declares a page title and renders a componentB
. I'd likeB
to also declare a page title, but conditionally. My first attempt was to use the following code:I was expecting the title from
A
to be shown when the empty string was returned. However, it was counted as a valid title ofB
. Then I triednull
and got the same result (it turned out being the same only because I was using the title template in the root component - otherwiseundefined
would be set as a title!). Finally I changed it toundefined
and it worked as expected, but TypeScript wasn't happy with that because returningundefined
is illegal.You can play around with this behavior in the reproduction, changing the return value in
HelloWorld.vue
.My suggestion is to either allow returning
undefined
, or, which is probably better because I don't understand whynull
is allowed and how it would be different fromundefined
- treatnull
as howundefined
is currently treated. Or maybe bothnull
andundefined
should be allowed (like in the most of other properties of the composable) and have the equivalent behavior.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: