From 403992eb320194d584f93429d936d44302a344c2 Mon Sep 17 00:00:00 2001 From: nick shook Date: Tue, 21 Apr 2020 06:59:08 -0700 Subject: [PATCH] fix(gatsby): fix Uncaught TypeError in navigation.js (#23196) * Add null check to address #21263 https://github.com/gatsbyjs/gatsby/issues/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 * chore: format Co-authored-by: Vladimir Razuvaev Co-authored-by: gatsbybot --- packages/gatsby/cache-dir/navigation.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/gatsby/cache-dir/navigation.js b/packages/gatsby/cache-dir/navigation.js index 4f71ee4cc6cbb..71d0e1feb8627 100644 --- a/packages/gatsby/cache-dir/navigation.js +++ b/packages/gatsby/cache-dir/navigation.js @@ -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 }