Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(head): allow using the default slot for script content like noscr…
Browse files Browse the repository at this point in the history
…ipt (#7858)

Co-authored-by: Martin Benndorf <martin.benndorf@gothaer.de>
  • Loading branch information
MiniDigger and Martin Benndorf committed Oct 3, 2022
1 parent e6ca07b commit 63c8805
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/composables/use-head/app.vue
Expand Up @@ -12,6 +12,7 @@
<Title>Luck number: {{ dynamic }}</Title>
<Meta name="description" :content="`My page's ${dynamic} description`" />
<Link rel="preload" href="/test.txt" as="script" />
<Script>console.log("hello script");</Script>
</Head>
</Html>
Expand Down
16 changes: 13 additions & 3 deletions packages/nuxt/src/head/runtime/components.ts
Expand Up @@ -90,9 +90,19 @@ export const Script = defineComponent({
/** @deprecated **/
language: String
},
setup: setupForUseMeta(script => ({
script: [script]
}))
setup: setupForUseMeta((props, { slots }) => {
const script = { ...props }
const textContent = (slots.default?.() || [])
.filter(({ children }) => children)
.map(({ children }) => children)
.join('')
if (textContent) {
script.children = textContent
}
return {
script: [script]
}
})
})

// <noscript>
Expand Down

0 comments on commit 63c8805

Please sign in to comment.