Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): e.remove() is not a function when using Gatsby Head API #36338

Merged
merged 4 commits into from
Aug 11, 2022
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