Support using textContent of <Script> head component #15033
Closed
Description
Describe the feature
When trying to setup my metadata, I need to inject some JS (GTM stuff), so I did use the <Script> tag, but was surprised to see, that you are required to use the children prob and cant use the textContent/default slot, is there any reason for that?
I tested locally that adding
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]
};
})
into the setup function of the script component (https://github.com/nuxt/framework/blob/2e080c259fc5068fcc71e3790b4f5b75cef83eea/packages/nuxt/src/head/runtime/components.ts#L94, similarly to the noscript or style tags below) works just fine, so I would PR that as a solution if this feature request is accepted, but I want to hear your thoughts first before I setup a workspace.
Additional information
- Would you be willing to help implement this feature?
- Could this feature be implemented as a module?
Final checks
- Read the contribution guide.
- Check existing discussions and issues.
Activity