-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[$250] Web - Notification count in the tab flashes when back is clicked #29604
Comments
Triggered auto assignment to @MitchExpensify ( |
Job added to Upwork: https://www.upwork.com/jobs/~011757bc5f159e3e7a |
Bug0 Triage Checklist (Main S/O)
|
Triggered auto assignment to Contributor-plus team member for initial proposal review - @akinwale ( |
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open
|
Triggered auto assignment to @Li357 ( |
Nor teproducible in production bandicam.2023-10-14.17-00-23-295.mp4 |
I think this is not a bug because when you hit the back button notification count is wrong in Production this flicker will happen when we update the new count. so here we are fixing when you hit the back button we are updating the correct count #29409 |
I can still reproduce this on latest main on MacOS: Chrome. The reason why some might not be able to reproduce this is because it's a Chromium engine specific issue hence why @pradeepmdk might have missed it in his PR #29409 VideoMacOS: ChromeScreen.Recording.2023-10-14.at.19.08.32.movProposalPlease re-state the problem that we are trying to solve in this issueNotification count in the tab flashes when back is clicked. What is the root cause of that problem?This is due to the way Chromium based browsers handle their tab management - it maintains a snapshot of the title and favicon and re-uses it briefly when navigating. Browsers do have some freedom in exactly when they fire popstate events, and Chrome seems to do it before the new page has fully loaded - hence the flickering of notification count on Chrome. The issue is caused by the logic in this file: App/src/libs/UnreadIndicatorUpdater/updateUnread/index.website.js Lines 6 to 14 in fe282b4
Because this does not handle Chrome's behaviour when it comes to tab management and therefore on Chrome the state of the snapshot is keept hence the flash of old notification count before being updated with the current one. What changes do you think we should make in order to solve the problem?My approach which will handle this issue for all browsers (including Chromium based) is to use window's - let unreadTotalCount = 0;
function updateUnread(totalCount) {
const hasUnread = totalCount !== 0;
- unreadTotalCount = totalCount;
// This setTimeout is required because due to how react rendering messes with the DOM, the document title can't be modified synchronously, and we must wait until all JS is done
// running before setting the title.
setTimeout(() => {
// 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;
// Update the browser history with a new title and favicon, instead of letting it remember the old state
// This is used because a side effect in Chromium based browsers where browser creates snapshots
// of the page state and re-uses them when navigating, causing a brief "flash" of the old title/favicon
+ window.history.replaceState({unreadTotalCount: totalCount}, document.title);
}, 0);
}
// Update the title and favicon when the user navigates to a history state that we pushed.
- window.addEventListener('popstate', () => {
+ window.addEventListener('popstate', event => {
+ if (!((event.state && "unreadTotalCount" in event.state))) {
+ return;
+ }
- updateUnread(unreadTotalCount);
+ updateUnread(event.state.unreadTotalCount);
}); What alternative solutions did you explore? (Optional)N/A VideosMacOS: ChromeScreen.Recording.2023-10-14.at.18.37.15.movScreen.Recording.2023-10-14.at.18.35.46.mov |
@ikevin127 see the notification count in the resulting video when you hit back count increases. |
@ikevin127 Your proposed solution has a flaw where the unread count in the browser title ends up being incorrect. It should maintain the current unread count after clicking the back button. In any case, if valid, this may end up being considered as a regression of the PR #29409 which would require the original PR author to fix it. We'll have to wait for feedback from an internal engineer. |
Indeed, I know that the counter increases when going back from reading a notification. Seeing this comment's video #29604 (comment) I thought that's the intended behaviour as that's how it is currently on staging. |
Upwork job price has been updated to $250 |
I agree this is not a blocker so removing the label, however we should still investigate this unless it will be covered by @pradeepmdk PR |
I do believe this is a regression from #29409 so it makes sense for the PR author @pradeepmdk to handle. cc: @sobitneupane |
@MariaHCD I think this is not a regression this is expected behavior only. Here when we click the browser back button it will load from browser history at the time in the navigation state whatever stored it retrieved. so the count is not updated in history so we are updating the new count while clicking the browser button. when we update the new count more fast flashes occur. we can use setTimeout for delay updates but that is not a good practice. |
I can confirm that this is not a regression. I consider this a browser level limitation / issue.
|
There is some disagreement around whether this is a regression. @MariaHCD what do you think about what @pradeepmdk and @ikevin127 are saying? |
Oh, interesting. Thanks @pradeepmdk and @ikevin127! This does look like a browser-level limitation. So not a regression, then. Perhaps there won't be a clean solution for this so I'd say if we don't find a good solution, we can close this one out. Thoughts, @akinwale? |
@MariaHCD Since it's not a regression, the proposal by @ikevin127 could work in this scenario using history.replaceState (reference), where the unread count is being stored in the browser's history state. @ikevin127 Could you please update your proposal and provide a video to demonstrate the expected behaviour with the unread count? Is it also possible to get rid of the |
@akinwale There's a catch with my current proposal:
MacOS: Chrome ExampleScreen.Recording.2023-10-14.at.18.35.46.movSo there's a choice here to be made between the following options:
Based on what's decided here I can update my proposal. As for getting rid of the current implementation's
we might break the current functionality if removed. I'll make sure to check when updating my proposal if we get there. |
If we go with this (we can use |
To answer your question: no. After further testing on the current implementation that's on staging I can confirm that on Chrome the following happens:
So I guess that this flicker thing was always there on Chrome as the PR author showed here for Gmail and this PR #29409 only exposed it to where it can be observed. I wouldn't count this behaviour as a regression, as I said before its more of a browser-level limitation. Solution if the flicker is really not wanted while logged in and navigating back / forward:The only way to get rid of the flicker would be to allow the notifications to increment back up on Chrome while logged in. If the user reads some messages then performs logout and then hits the forward button, we will keep the current implementation with the flicker because when upon logout it's less likely that users would hit the forward button and see the flicker. It's more likely to be seen while logged in and hitting back button while reading through reports. ^ - This would be the behaviour for Chromium based browsers. For all other browsers the current implementation works as expected, no flickers both logged in back / forward buttons and upon logout back / forward buttons. Would look like this on ChromeScreen.Recording.2023-10-18.at.00.14.32.movIf this solution is something that would work for you, I can update my proposal with the solution described above. |
@MariaHCD Considering the discussion above, looks like we may have to close this since it's a browser limitation. |
I'd agree with closing since it's a browser limitation. Leaving the final decision to the assigned folks here, @Li357 and @MitchExpensify |
lets do it |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Issue found when executing PR #29409
Version Number: v1.3.84-0
Reproducible in staging?: Y
Reproducible in production?: N
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation: @
Action Performed:
Expected Result:
Notification count should be the same
Actual Result:
Notification count in the tab flashes when back is clicked
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Bug6236815_1697275265599.notification_count.mp4
MacOS: Desktop
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: