From 63c88056c759111effa7094953010c840955ea8d Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Mon, 3 Oct 2022 16:16:37 +0200 Subject: [PATCH] fix(head): allow using the default slot for script content like noscript (#7858) Co-authored-by: Martin Benndorf --- examples/composables/use-head/app.vue | 1 + packages/nuxt/src/head/runtime/components.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/composables/use-head/app.vue b/examples/composables/use-head/app.vue index 335ffbd8f90..3c19f0731ac 100644 --- a/examples/composables/use-head/app.vue +++ b/examples/composables/use-head/app.vue @@ -12,6 +12,7 @@ Luck number: {{ dynamic }} + diff --git a/packages/nuxt/src/head/runtime/components.ts b/packages/nuxt/src/head/runtime/components.ts index df8ff0aed9a..db72e444ce8 100644 --- a/packages/nuxt/src/head/runtime/components.ts +++ b/packages/nuxt/src/head/runtime/components.ts @@ -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] + } + }) }) //