Skip to content

Commit

Permalink
add new elements and remove stale ones
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinjude committed Jul 27, 2022
1 parent 3e660c1 commit ae3d0d6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/gatsby/cache-dir/head/head-export-handler-for-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,31 @@ const onHeadRendered = () => {
...document.querySelectorAll(`[data-gatsby-head]`),
]

if (existingHeadElements.length === 0) {
document.head.append(...validHeadNodes)
return
}

const elementsToRemove = []

for (const existingHeadElement of existingHeadElements) {
const isInValidNodes = validHeadNodes.some(e =>
isEqualNode(e, existingHeadElement)
)

if (!isInValidNodes) {
elementsToRemove.push(existingHeadElement)
}
}

elementsToRemove.forEach(e => e.remove())

for (const validHeadNode of validHeadNodes) {
const isInExistingHead = existingHeadElements.some(e =>
const isInExistingHeadElementsList = existingHeadElements.some(e =>
isEqualNode(e, validHeadNode)
)

if (!isInExistingHead) {
if (!isInExistingHeadElementsList) {
diffedHeadNodes.push(validHeadNode)
}
}
Expand Down

0 comments on commit ae3d0d6

Please sign in to comment.