diff --git a/packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js b/packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js
index 2003321cf71cb..88c837f7e6d61 100644
--- a/packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js
+++ b/packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js
@@ -56,20 +56,31 @@ export function headHandlerForSSR({
const seenIds = new Map()
for (const node of headNodes) {
- const { rawTagName, attributes } = node
- const id = attributes.id
+ const { rawTagName } = node
+ const id = node.attributes.id
if (!VALID_NODE_NAMES.includes(rawTagName)) {
warnForInvalidTags(rawTagName)
} else {
- const element = createElement(
- rawTagName,
- {
- ...attributes,
- "data-gatsby-head": true,
- },
- node.childNodes[0]?.textContent
- )
+ let element
+ const attributes = { ...node.attributes, "data-gatsby-head": true }
+ if (rawTagName === `script`) {
+ element = (
+
+ )
+ } else {
+ element = (
+
+ {node.childNodes[0]?.textContent}
+
+ )
+ }
+
if (id) {
if (!seenIds.has(id)) {
validHeadNodes.push(element)