Skip to content

Commit

Permalink
fix(gatsby): Prevent errors if Head has root text node (#36402)
Browse files Browse the repository at this point in the history
* Don't break when Head has root text node(s)

* test that we dont break on root text nodes
  • Loading branch information
marvinjude committed Aug 18, 2022
1 parent 9d737b6 commit a05201e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
Expand Up @@ -60,6 +60,7 @@ export function Head() {
<script type="text/javascript">
{`window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ = (window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ || 0 ) + 1`}
</script>
Adding-this-text-here-should-not-break-things
</>
)
}
Expand Up @@ -41,6 +41,7 @@ export function Head() {
<script type="text/javascript">
{`window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ = (window.__SOME_GLOBAL_TO_CHECK_CALL_COUNT__ || 0 ) + 1`}
</script>
Adding-this-text-here-should-not-break-things
</>
)
}
Expand Up @@ -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)
Expand Down
Expand Up @@ -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)
Expand Down

0 comments on commit a05201e

Please sign in to comment.