harlan-zw / nuxt-seo

The complete SEO solution for Nuxt.
https://nuxtseo.com
1.05k stars 67 forks source link

calling `useSchemaOrg("")` with empty input adds empty element to the `@graph` #336

Open KajKandler opened 1 day ago

KajKandler commented 1 day ago

Describe the bug

I have the following code in my [...slug].vue file in Nuxt Content to add page specific schema

<script setup>
const route = useRoute()
const { data: page } = await useAsyncData('content', () => queryContent(route.path).findOne())

// Extract schema from the content's frontmatter
const schema = page.value.schema_org

// Use the nuxt-schema-org composable to add schema
if (schema !== undefined && schema != null) {
  useSchemaOrg(schema)
} else {
  useSchemaOrg("") // produces empty element in the '@graph' list
}
</script>

produces this output

<script type="application/ld+json" id="schema-org-graph">{
  "@context": "https://schema.org",
  "@graph": [
       {
         // ... my global schema
       }, 
    {}
  ]
}</script>

Reproduction

No response

System / Nuxt Info

------------------------------
- Operating System: Darwin
- Node Version:     v21.7.1
- Nuxt Version:     3.13.2
- CLI Version:      3.14.0
- Nitro Version:    2.9.7
- Package Manager:  npm@10.8.2
- Builder:          -
- User Config:      -
- Runtime Modules:  -
- Build Modules:    -
------------------------------
harlan-zw commented 20 hours ago

Hi, what is the expected output when providing useSchemaOrg(""), it's not really clear?