unjs / unhead

Unhead is the any-framework document head manager built for performance and delightful developer experience.
https://unhead.unjs.io
MIT License
641 stars 41 forks source link

@unhead/addons/vite breaks when a spread operator is used in useSeoMeta function during build #159

Closed lavolpecheprogramma closed 1 year ago

lavolpecheprogramma commented 1 year ago

Environment

"@unhead/addons": "^1.1.27",

node 18.12.1

Reproduction

i have my custom function that wrap useSeoMeta that allow me to use some default seo datas

export function useSeo (data: UseSeoMetaInput) {
  const entry = useSeoMeta({
    twitterCard: 'summary_large_image',
    ...data,
    description: () => toValue(data.description) || toValue(defaults.siteDescription),
    ogDescription: () => toValue(data.ogDescription) || toValue(data.description) || toValue(defaults.siteDescription),
    ogTitle: () => toValue(data.ogTitle) || toValue(data.title) || toValue(defaults.siteName),
    ogImage: () => toValue(data.ogImage) || toValue(defaults.defaultImage)
  })

  onUnmounted(() => entry && entry.dispose())
}

that i call from my component

like this

useSeo({ title: 'Login' })

Describe the bug

the error in console is:

[unhead:use-seo-meta-transform] Cannot read properties of undefined (reading 'type')
error during build:
TypeError: Cannot read properties of undefined (reading 'type')

this is the line that throw the error and i think that this happen because the spread node element doesn't have the "key" property

thanks in advance

Additional context

No response

Logs

No response

harlan-zw commented 1 year ago

Hey @lavolpecheprogramma, thanks for the issue and sorry about the delay.

This should be fixed in v1.1.28. I don't think it's possible to support the spread operator so it will just fallback to not treeshaking.