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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(head): allow using the default slot for script content
  • Loading branch information
Martin Benndorf committed Sep 27, 2022
commit f7e45c92c67c1c29ead2d78afe433e103b1fd2ef
1 change: 1 addition & 0 deletions examples/composables/use-head/app.vue
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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