Skip to content

Commit e40ea25

Browse files
fix: fix double ws connection for notifications (coder#17044)
**Issue:** The UI was creating two web socket connections to receive notification updates causing duplicated values. **Cause:** We were rendering the notification container twice. One for the desktop nav and another for mobile. **Fix:** Only use one notification container for the nav. **Improvements for later:** I think would be better at some point to move the networking and data logic into a provider but it would require testing and some tiny rework. Since the actual fix works well, and it is not complex or difficult, I think it is ok to stay with it until we require to load notifications in more places.
1 parent 1593861 commit e40ea25

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

site/src/modules/dashboard/Navbar/NavbarView.tsx

+30-34
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ export const NavbarView: FC<NavbarViewProps> = ({
5555

5656
<NavItems className="ml-4" />
5757

58-
<div className="hidden md:flex items-center gap-3 ml-auto">
58+
<div className="flex items-center gap-3 ml-auto">
5959
{proxyContextValue && (
60-
<ProxyMenu proxyContextValue={proxyContextValue} />
60+
<div className="hidden md:block">
61+
<ProxyMenu proxyContextValue={proxyContextValue} />
62+
</div>
6163
)}
6264

63-
<DeploymentDropdown
64-
canViewAuditLog={canViewAuditLog}
65-
canViewOrganizations={canViewOrganizations}
66-
canViewDeployment={canViewDeployment}
67-
canViewHealth={canViewHealth}
68-
/>
65+
<div className="hidden md:block">
66+
<DeploymentDropdown
67+
canViewAuditLog={canViewAuditLog}
68+
canViewOrganizations={canViewOrganizations}
69+
canViewDeployment={canViewDeployment}
70+
canViewHealth={canViewHealth}
71+
/>
72+
</div>
6973

7074
<NotificationsInbox
7175
fetchNotifications={API.getInboxNotifications}
@@ -78,36 +82,28 @@ export const NavbarView: FC<NavbarViewProps> = ({
7882
/>
7983

8084
{user && (
81-
<UserDropdown
85+
<div className="hidden md:block">
86+
<UserDropdown
87+
user={user}
88+
buildInfo={buildInfo}
89+
supportLinks={supportLinks}
90+
onSignOut={onSignOut}
91+
/>
92+
</div>
93+
)}
94+
95+
<div className="md:hidden">
96+
<MobileMenu
97+
proxyContextValue={proxyContextValue}
8298
user={user}
83-
buildInfo={buildInfo}
8499
supportLinks={supportLinks}
85100
onSignOut={onSignOut}
101+
canViewAuditLog={canViewAuditLog}
102+
canViewOrganizations={canViewOrganizations}
103+
canViewDeployment={canViewDeployment}
104+
canViewHealth={canViewHealth}
86105
/>
87-
)}
88-
</div>
89-
90-
<div className="ml-auto flex items-center gap-3 md:hidden">
91-
<NotificationsInbox
92-
fetchNotifications={API.getInboxNotifications}
93-
markAllAsRead={API.markAllInboxNotificationsAsRead}
94-
markNotificationAsRead={(notificationId) =>
95-
API.updateInboxNotificationReadStatus(notificationId, {
96-
is_read: true,
97-
})
98-
}
99-
/>
100-
101-
<MobileMenu
102-
proxyContextValue={proxyContextValue}
103-
user={user}
104-
supportLinks={supportLinks}
105-
onSignOut={onSignOut}
106-
canViewAuditLog={canViewAuditLog}
107-
canViewOrganizations={canViewOrganizations}
108-
canViewDeployment={canViewDeployment}
109-
canViewHealth={canViewHealth}
110-
/>
106+
</div>
111107
</div>
112108
</div>
113109
);

0 commit comments

Comments
 (0)