-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Conversation
@@ -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()) |
There was a problem hiding this comment.
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 [...]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
0cf3611
to
c971686
Compare
Description
Adding a custom babel config with the
loose
option set tofalse
causes some conversion that leads the error belowThis PR fixes it by directly iterating over the NodeLists without creating new arrays and removing unnecessary spread operators
Also address issue with IE not having
.remove()
by usingnode.parentNode.removeChild(node)
Documentation
https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-head/
Related Issues
Fixes #36247