Skip to content

Commit

Permalink
fix(gatsby): fix Uncaught TypeError in navigation.js (gatsbyjs#23196)
Browse files Browse the repository at this point in the history
* Add null check to address gatsbyjs#21263

gatsbyjs#21263 is an issue many people are arriving at for a variety of reasons.  Since the code contains this logic on the following line:

```
      if (pageHeadings && pageHeadings.length) {
```

There should be no issue in seeing if `document.getElementById(`gatsby-focus-wrapper`) exists first before attempting to look up `getElementsByTagName`.

* Update packages/gatsby/cache-dir/navigation.js

Co-Authored-By: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>

* chore: format

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
3 people authored and johno committed Apr 21, 2020
1 parent a6cc113 commit 403992e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions packages/gatsby/cache-dir/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ class RouteAnnouncer extends React.Component {
if (document.title) {
pageName = document.title
}
const pageHeadings = document
.getElementById(`gatsby-focus-wrapper`)
.getElementsByTagName(`h1`)
const pageHeadings = document.querySelectorAll(`#gatsby-focus-wrapper h1`)
if (pageHeadings && pageHeadings.length) {
pageName = pageHeadings[0].textContent
}
Expand Down

0 comments on commit 403992e

Please sign in to comment.