From 7a233927fd25e002b5ea0e962cdb5ad1fe5f2382 Mon Sep 17 00:00:00 2001 From: Dede Hamzah Date: Mon, 11 May 2020 21:45:23 +0700 Subject: [PATCH] fix: handle nullish announcementRef to fix client side redirect error (#23956) --- packages/gatsby/cache-dir/navigation.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/cache-dir/navigation.js b/packages/gatsby/cache-dir/navigation.js index 701871a6e704f..b3f22f6e4de5f 100644 --- a/packages/gatsby/cache-dir/navigation.js +++ b/packages/gatsby/cache-dir/navigation.js @@ -174,9 +174,11 @@ class RouteAnnouncer extends React.Component { pageName = pageHeadings[0].textContent } const newAnnouncement = `Navigated to ${pageName}` - const oldAnnouncement = this.announcementRef.current.innerText - if (oldAnnouncement !== newAnnouncement) { - this.announcementRef.current.innerText = newAnnouncement + if (this.announcementRef.current) { + const oldAnnouncement = this.announcementRef.current.innerText + if (oldAnnouncement !== newAnnouncement) { + this.announcementRef.current.innerText = newAnnouncement + } } }) }