From bfcd7033fdbd5569f09823be5bc21f2f05e36d84 Mon Sep 17 00:00:00 2001 From: anshika1179 Date: Tue, 4 Aug 2026 16:06:46 +0530 Subject: [PATCH] fix: instantly increment unread badge on realtime insert (#1911) --- src/features/notifications/useNotifications.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/features/notifications/useNotifications.ts b/src/features/notifications/useNotifications.ts index 8820f1e7..2e000078 100644 --- a/src/features/notifications/useNotifications.ts +++ b/src/features/notifications/useNotifications.ts @@ -164,9 +164,10 @@ export function useNotifications(userId?: string) { return [incoming, ...current]; }); - // Re-fetch the authoritative unread count rather than incrementing - // locally, since the loaded page may not include every notification. - fetchUnreadCount(); + // Increment locally since Realtime can sometimes beat the read replica + if (!incoming.read) { + setUnreadCount((current) => current + 1); + } // Check focus mode before showing popup supabase.from('profiles').select('is_in_focus_mode').eq('id', userId).single().then(({ data }) => {