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

Commit 63c8805

Browse files
MiniDiggerMartin Benndorf
andauthored
fix(head): allow using the default slot for script content like noscript (#7858)
Co-authored-by: Martin Benndorf <[email protected]>
1 parent e6ca07b commit 63c8805

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

examples/composables/use-head/app.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Title>Luck number: {{ dynamic }}</Title>
1313
<Meta name="description" :content="`My page's ${dynamic} description`" />
1414
<Link rel="preload" href="/test.txt" as="script" />
15+
<Script>console.log("hello script");</Script>
1516
</Head>
1617
</Html>
1718

packages/nuxt/src/head/runtime/components.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,19 @@ export const Script = defineComponent({
9090
/** @deprecated **/
9191
language: String
9292
},
93-
setup: setupForUseMeta(script => ({
94-
script: [script]
95-
}))
93+
setup: setupForUseMeta((props, { slots }) => {
94+
const script = { ...props }
95+
const textContent = (slots.default?.() || [])
96+
.filter(({ children }) => children)
97+
.map(({ children }) => children)
98+
.join('')
99+
if (textContent) {
100+
script.children = textContent
101+
}
102+
return {
103+
script: [script]
104+
}
105+
})
96106
})
97107

98108
// <noscript>

0 commit comments

Comments
 (0)