From ba375058360dafe4c5cd5b256af1afdbfaac7d88 Mon Sep 17 00:00:00 2001 From: zhongyua Date: Tue, 28 Apr 2026 11:44:06 +0800 Subject: [PATCH] fix(frontend): notification panel never fetches list on bell click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bell's onClick called refetchNotifications() synchronously after setShowNotifications(v => !v). At that moment useQuery is still enabled: false (state hasn't committed), so the manual refetch never hit /api/notifications -- empirically 0 list calls vs 300+ unread-count polls in dev logs. The panel always showed "暂无通知" and the unread badge could never decrement (no list = nothing to mark as read). Drop the manual refetch and let v5 auto-fetch when enabled flips false -> true (queryObserver.shouldFetchOptionally already covers this). Co-Authored-By: Claude Opus 4.7 --- frontend/src/pages/Layout.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Layout.tsx b/frontend/src/pages/Layout.tsx index 34f7f825f..7f37b19e0 100644 --- a/frontend/src/pages/Layout.tsx +++ b/frontend/src/pages/Layout.tsx @@ -269,7 +269,7 @@ export default function Layout() { refetchInterval: 30000, enabled: !!user, }); - const { data: notifications = [], refetch: refetchNotifications } = useQuery({ + const { data: notifications = [] } = useQuery({ queryKey: ['notifications', notifCategory], queryFn: () => fetchJson(`/notifications?limit=50${notifCategory !== 'all' ? `&category=${notifCategory}` : ''}`), enabled: !!user && showNotifications, @@ -731,7 +731,7 @@ export default function Layout() { }} title={theme === 'dark' ? t('common.lightMode') : t('common.darkMode')}> {theme === 'dark' ? SidebarIcons.sun : SidebarIcons.moon} -