From ef2795d61f04c4d13f0d3e7d55bd4ac557d4e3bc Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Fri, 26 Dec 2025 10:44:53 +0300 Subject: [PATCH] Update query cache and invalidate on WS message Make ws.onmessage async, use functional setQueryData calls, and await invalidateQueries for feed, now-playings, and scrobblesChart so consumers receive fresh data after WebSocket updates --- apps/web/src/pages/home/feed/Feed.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/web/src/pages/home/feed/Feed.tsx b/apps/web/src/pages/home/feed/Feed.tsx index da9bfedb..0bdefde2 100644 --- a/apps/web/src/pages/home/feed/Feed.tsx +++ b/apps/web/src/pages/home/feed/Feed.tsx @@ -46,15 +46,22 @@ function Feed() { }, 3000); }; - ws.onmessage = (event) => { + ws.onmessage = async (event) => { if (event.data === "pong") { return; } const message = JSON.parse(event.data); - queryClient.setQueryData(["feed"], message.scrobbles); - queryClient.setQueryData(["now-playings"], message.nowPlayings); - queryClient.setQueryData(["scrobblesChart"], message.scrobblesChart); + queryClient.setQueryData(["feed"], () => message.scrobbles); + queryClient.setQueryData(["now-playings"], () => message.nowPlayings); + queryClient.setQueryData( + ["scrobblesChart"], + () => message.scrobblesChart, + ); + + await queryClient.invalidateQueries({ queryKey: ["feed"] }); + await queryClient.invalidateQueries({ queryKey: ["now-playings"] }); + await queryClient.invalidateQueries({ queryKey: ["scrobblesChart"] }); }; return () => { -- 2.51.2