Skip to content

Commit

Permalink
Merge pull request #11160 from Expensify/marcaaron-fixWebTitleIndicator
Browse files Browse the repository at this point in the history
Fix incorrect webpage title on back button press (chrome bug)
  • Loading branch information
marcaaron authored Oct 6, 2022
2 parents 156fd61 + 321dc8e commit 5df0171
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libs/UnreadIndicatorUpdater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5df0171

Please sign in to comment.