Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
const hiddenRoot = document.createElement(`div`)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break in older browser versions where nodeList does not contain forEach. You'll have to figure out the issue differently. What exactly is the issue with [...]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is the issue with [...]?

#36247 (comment)

Good catch 👍 I'd do a for...of instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you change it into Array.from ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.from works fine — turns out we didn't even need to create new arrays in the first place

}

Expand Down Expand Up @@ -58,9 +58,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 Down