fix(frontend): land SSE notification updates in the cache keys readers use - #1726
Open
Oyintarede wants to merge 1 commit into
Open
fix(frontend): land SSE notification updates in the cache keys readers use#1726Oyintarede wants to merge 1 commit into
Oyintarede wants to merge 1 commit into
Conversation
…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>
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.
Closes #1071
Summary
The live notifications SSE stream (
useNotificationStream) pushed incoming notifications into the TanStack Query cache withqueryClient.setQueryData(queryKeys.notifications.all()), which targets the exact key["notifications"]. But nothing reads that key:useNotifications()→["notifications", {}]useNotifications({ limit, type, unread })→["notifications", { limit, type, unread }]Because
setQueryDataonly matches an exact key (unlikeinvalidateQueries, which matches by prefix), the write landed in a cache entry no component subscribes to. Live notifications therefore only appeared after the 60srefetchIntervalpoll — defeating the whole purpose of the SSE push.What changed
useNotificationStream.ts: switched fromsetQueryDatatoqueryClient.setQueriesData({ queryKey: queryKeys.notifications.all() }, updater).setQueriesDatawith a prefixqueryKeyfilter 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/linton this branch and are included so CI passes:useRepaymentOperation.ts:useRepaymentOperationreferencedqueryClientwithout auseQueryClient()binding — added it.WalletProvider.tsx: a Prettier formatting nit.Verified
npm test(234 tests pass),npm run lint, andnpm run typecheckgreen