Skip to content

fix(frontend): land SSE notification updates in the cache keys readers use - #1726

Open
Oyintarede wants to merge 1 commit into
LabsCrypt:mainfrom
Oyintarede:fix/notification-sse-cache-key
Open

fix(frontend): land SSE notification updates in the cache keys readers use#1726
Oyintarede wants to merge 1 commit into
LabsCrypt:mainfrom
Oyintarede:fix/notification-sse-cache-key

Conversation

@Oyintarede

Copy link
Copy Markdown

Closes #1071

Summary

The live notifications SSE stream (useNotificationStream) pushed incoming notifications into the TanStack Query cache with queryClient.setQueryData(queryKeys.notifications.all()), which targets the exact key ["notifications"]. But nothing reads that key:

  • the bell dropdown reads useNotifications()["notifications", {}]
  • the inbox page reads useNotifications({ limit, type, unread })["notifications", { limit, type, unread }]

Because setQueryData only matches an exact key (unlike invalidateQueries, which matches by prefix), the write landed in a cache entry no component subscribes to. Live notifications therefore only appeared after the 60s refetchInterval poll — defeating the whole purpose of the SSE push.

What changed

  • useNotificationStream.ts: switched from setQueryData to queryClient.setQueriesData({ queryKey: queryKeys.notifications.all() }, updater). setQueriesData with a prefix queryKey filter writes to every cache entry whose key starts with ["notifications"], so both the dropdown and inbox keys receive the update immediately. The init-merge and unread-count logic is unchanged.
  • useNotificationStream.test.tsx (new): regression test asserting that (1) a streamed notification appears in the list reader's cache entry without waiting for the 60s poll, and (2) init merges and unread-count recomputation still work on the list key.

Incidental fixes (pre-existing)

While verifying the change, two unrelated issues blocked a green typecheck/lint on this branch and are included so CI passes:

  • useRepaymentOperation.ts: useRepaymentOperation referenced queryClient without a useQueryClient() binding — added it.
  • WalletProvider.tsx: a Prettier formatting nit.

Verified

  • Stream updates land in the same cache entry the dropdown and inbox read
  • A pushed notification shows up in the bell/inbox without waiting for the 60s poll
  • Init-merge and unread-count still work after the key change
  • New test asserts a streamed notification updates the rendered list
  • npm test (234 tests pass), npm run lint, and npm run typecheck green

Out of scope (per issue): backend SSE behavior and action_url deep-linking.

…s use

The notifications SSE stream wrote incoming notifications via
setQueryData(queryKeys.notifications.all()) — the exact key ["notifications"].
Because setQueryData only matches an exact key, the update landed in a cache
entry no component subscribed to (the bell dropdown reads
["notifications", {}] and the inbox page ["notifications", {limit,type,unread}]),
so live notifications only appeared after the 60s poll refetched.

Switch the stream to setQueriesData with a prefix-queryKey filter so the write is
applied to every list entry whose key starts with ["notifications"], keeping the
init-merge and unread-count math intact while making pushed notifications render
immediately.

Add a regression test that a streamed (non-polled) notification appears in the
list reader's cache entry, and that init-merge/unread counts still hold after the
key change.

Also fix two pre-existing issues that kept typecheck/lint from passing on this
branch: useRepaymentOperation referenced queryClient without a useQueryClient
binding, and WalletProvider.tsx had a formatting nit.

Closes LabsCrypt#1071

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Frontend] Notification SSE writes to a query key the UI never reads, so live notifications only appear after the 60s poll

1 participant