From 321dc8ee0f83b7f6896288830051e29face9e74a Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 20 Sep 2022 20:46:05 -1000 Subject: [PATCH] Fix incorrect webpage title on back button press (chrome bug) --- src/libs/UnreadIndicatorUpdater/index.js | 7 ++++--- .../UnreadIndicatorUpdater/updateUnread/index.website.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libs/UnreadIndicatorUpdater/index.js b/src/libs/UnreadIndicatorUpdater/index.js index e4b21ddea4be..4cf82b19d376 100644 --- a/src/libs/UnreadIndicatorUpdater/index.js +++ b/src/libs/UnreadIndicatorUpdater/index.js @@ -7,13 +7,14 @@ import * as ReportUtils from '../ReportUtils'; const reports = {}; /** - * Updates the title and favicon of the current browser tab - * and Mac OS or iOS dock icon with an unread indicator. + * Updates the title and favicon of the current browser tab and Mac OS or iOS dock icon with an unread indicator. + * Note: We are throttling this since listening for report changes can trigger many updates depending on how many reports + * a user has and how often they are updated. */ const throttledUpdatePageTitleAndUnreadCount = _.throttle(() => { const totalCount = _.filter(reports, ReportUtils.isUnread).length; updateUnread(totalCount); -}, 1000, {leading: false}); +}, 100, {leading: false}); let connectionID; diff --git a/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js b/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js index 75f6d3f31d08..c39afe29551b 100644 --- a/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js +++ b/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js @@ -10,6 +10,10 @@ import CONFIG from '../../../CONFIG'; */ function updateUnread(totalCount) { const hasUnread = totalCount !== 0; + + // There is a Chrome browser bug that causes the title to revert back to the previous when we are navigating back. Setting the title to an empty string + // seems to improve this issue. + document.title = ''; document.title = hasUnread ? `(${totalCount}) ${CONFIG.SITE_TITLE}` : CONFIG.SITE_TITLE; document.getElementById('favicon').href = hasUnread ? CONFIG.FAVICON.UNREAD : CONFIG.FAVICON.DEFAULT; }