diff --git a/e2e-tests/development-runtime/src/pages/head-function-export/basic.js b/e2e-tests/development-runtime/src/pages/head-function-export/basic.js
index a79609b1f240d..d933cec2f0d2c 100644
--- a/e2e-tests/development-runtime/src/pages/head-function-export/basic.js
+++ b/e2e-tests/development-runtime/src/pages/head-function-export/basic.js
@@ -60,6 +60,7 @@ export function Head() {
+ Adding-this-text-here-should-not-break-things
>
)
}
diff --git a/e2e-tests/production-runtime/src/pages/head-function-export/basic.js b/e2e-tests/production-runtime/src/pages/head-function-export/basic.js
index e2bad20c6174f..53117df670295 100644
--- a/e2e-tests/production-runtime/src/pages/head-function-export/basic.js
+++ b/e2e-tests/production-runtime/src/pages/head-function-export/basic.js
@@ -41,6 +41,7 @@ export function Head() {
+ Adding-this-text-here-should-not-break-things
>
)
}
diff --git a/packages/gatsby/cache-dir/head/head-export-handler-for-browser.js b/packages/gatsby/cache-dir/head/head-export-handler-for-browser.js
index f13bb7bfc093a..48a58ca27d3f2 100644
--- a/packages/gatsby/cache-dir/head/head-export-handler-for-browser.js
+++ b/packages/gatsby/cache-dir/head/head-export-handler-for-browser.js
@@ -28,7 +28,7 @@ const onHeadRendered = () => {
const seenIds = new Map()
for (const node of hiddenRoot.childNodes) {
const nodeName = node.nodeName.toLowerCase()
- const id = node.attributes.id?.value
+ const id = node.attributes?.id?.value
if (!VALID_NODE_NAMES.includes(nodeName)) {
warnForInvalidTags(nodeName)
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 88c837f7e6d61..41e3bd141d967 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
@@ -57,7 +57,7 @@ export function headHandlerForSSR({
const seenIds = new Map()
for (const node of headNodes) {
const { rawTagName } = node
- const id = node.attributes.id
+ const id = node.attributes?.id
if (!VALID_NODE_NAMES.includes(rawTagName)) {
warnForInvalidTags(rawTagName)