fix(frontend): notification panel never fetches list on bell click#495
Open
TatsuKo-Tsukimi wants to merge 1 commit intodataelement:mainfrom
Open
fix(frontend): notification panel never fetches list on bell click#495TatsuKo-Tsukimi wants to merge 1 commit intodataelement:mainfrom
TatsuKo-Tsukimi wants to merge 1 commit intodataelement:mainfrom
Conversation
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 <noreply@anthropic.com>
Author
|
Note on local repro — heard this isn't manifesting on at least one local dev setup. A couple of things that may help isolate it: Reproduction checklist:
The buggy state and the no-unread state look identical in the panel ("暂无通知"), so the network tab is the reliable signal. Possible dev-vs-prod divergence: Verification here was on a
None of these are things I could prove from a static read; they're just common axes for "works in dev, broken in prod" discrepancies. Empirical state on the deployed dev env (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Clicking the notification bell opens the panel but always shows "暂无通知 / No notifications" even when the unread badge displays a positive count. The unread number then stays stuck — closing and reopening doesn't help.
Root cause
Layout.tsxcallsrefetchNotifications()synchronously inside the bell's onClick, right aftersetShowNotifications(v => !v). At that moment the query is stillenabled: !!user && showNotificationswithshowNotifications === false(state hasn't committed yet), so the manual refetch doesn't actually hit/api/notifications.Empirical evidence from dev backend logs: 300+ hits on
GET /api/notifications/unread-count(the polling badge), zero onGET /api/notifications(the list endpoint). With the list never fetched,notificationsstays[](the panel shows "暂无通知") andmarkOneRead/markAllReadare never reachable — that's why the badge can never decrement.Fix
Drop the manual refetch entirely. TanStack Query v5's
queryObserver.shouldFetchOptionallyalready auto-fetches whenenabledflipsfalse → true(theprevOptions.enabled === falsebranch with stale data).Verified on dev
After the fix, every bell interaction now produces the expected backend call:
GET /api/notifications?limit=50 → 200(panel populates)?category=tool|approval|social → 200eachPOST /api/notifications/{id}/read → 200(badge -1)POST /api/notifications/read-all → 200(badge → 0)