Skip to content

Commit a05201e

Browse files
authored
fix(gatsby): Prevent errors if Head has root text node (gatsbyjs#36402)
* Don't break when Head has root text node(s) * test that we dont break on root text nodes
1 parent 9d737b6 commit a05201e

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

e2e-tests/development-runtime/src/pages/head-function-export/basic.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function Head() {
6060
<script type="text/javascript">
6161
{`window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ = (window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ || 0 ) + 1`}
6262
</script>
63+
Adding-this-text-here-should-not-break-things
6364
</>
6465
)
6566
}

e2e-tests/production-runtime/src/pages/head-function-export/basic.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function Head() {
4141
<script type="text/javascript">
4242
{`window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ = (window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ || 0 ) + 1`}
4343
</script>
44+
Adding-this-text-here-should-not-break-things
4445
</>
4546
)
4647
}

packages/gatsby/cache-dir/head/head-export-handler-for-browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const onHeadRendered = () => {
2828
const seenIds = new Map()
2929
for (const node of hiddenRoot.childNodes) {
3030
const nodeName = node.nodeName.toLowerCase()
31-
const id = node.attributes.id?.value
31+
const id = node.attributes?.id?.value
3232

3333
if (!VALID_NODE_NAMES.includes(nodeName)) {
3434
warnForInvalidTags(nodeName)

packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function headHandlerForSSR({
5757
const seenIds = new Map()
5858
for (const node of headNodes) {
5959
const { rawTagName } = node
60-
const id = node.attributes.id
60+
const id = node.attributes?.id
6161

6262
if (!VALID_NODE_NAMES.includes(rawTagName)) {
6363
warnForInvalidTags(rawTagName)

0 commit comments

Comments
 (0)