Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/gatsby/cache-dir/head/head-export-handler-for-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import {
const hiddenRoot = document.createElement(`div`)

const removePrevHeadElements = () => {
const prevHeadNodes = [...document.querySelectorAll(`[data-gatsby-head]`)]
prevHeadNodes.forEach(e => e.remove())
const prevHeadNodes = document.querySelectorAll(`[data-gatsby-head]`)

for (const node of prevHeadNodes) {
node.parentNode.removeChild(node)
}
}

const onHeadRendered = () => {
Expand Down Expand Up @@ -49,7 +52,9 @@ const onHeadRendered = () => {
seenIds.set(id, validHeadNodes.length - 1)
} else {
const indexOfPreviouslyInsertedNode = seenIds.get(id)
validHeadNodes[indexOfPreviouslyInsertedNode].remove()
validHeadNodes[indexOfPreviouslyInsertedNode].parentNode?.removeChild(
validHeadNodes[indexOfPreviouslyInsertedNode]
)
validHeadNodes[indexOfPreviouslyInsertedNode] = clonedNode
}
} else {
Expand All @@ -58,9 +63,7 @@ const onHeadRendered = () => {
}
}

const existingHeadElements = [
...document.querySelectorAll(`[data-gatsby-head]`),
]
const existingHeadElements = document.querySelectorAll(`[data-gatsby-head]`)

if (existingHeadElements.length === 0) {
document.head.append(...validHeadNodes)
Expand All @@ -71,7 +74,7 @@ const onHeadRendered = () => {
diffNodes({
oldNodes: existingHeadElements,
newNodes: validHeadNodes,
onStale: node => node.remove(),
onStale: node => node.parentNode.removeChild(node),
onNew: node => newHeadNodes.push(node),
})

Expand Down