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

fix(head): allow using the default slot for script content like noscript #7858

Merged
merged 1 commit into from Oct 3, 2022
Merged
Show file tree
Hide file tree
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
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