Skip to content

Commit a0990d1

Browse files
[fix] Disconnect websocket on page reload to prevent missed notifications #264
When users click "Save" or "Save and Continue", the page reloads and closes the websocket connection. If a background task completes during this reload, the notification is lost because there's no active websocket connection to receive it. This change explicitly disconnects the websocket on beforeunload, ensuring the server knows the client is unavailable. When the page reloads and the websocket reconnects, any queued notifications will be delivered properly. Fixes #264
1 parent 0f3d262 commit a0990d1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

openwisp_notifications/static/openwisp-notifications/js/notifications.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const owNotificationWindow = {
3232
// closing the window
3333
$(window).on("beforeunload", function () {
3434
owNotificationWindow.remove();
35+
// Disconnect websocket to prevent missed notifications during page reload
36+
if (typeof notificationSocket !== "undefined") {
37+
notificationSocket.close();
38+
}
3539
});
3640
// Get authority to play notification sound when
3741
// other windows are closed

0 commit comments

Comments
 (0)