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

Co-authored-by: Martin Benndorf <martin.benndorf@gothaer.de>
This commit is contained in:
MiniDigger | Martin 2022-10-03 16:16:37 +02:00 committed by GitHub
parent e6ca07bdc0
commit 63c88056c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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>

View File

@ -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>