From 1a65b9c14dd19e8e9eb810bcbfa8673301144376 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 18:21:52 +0000 Subject: [PATCH 1/2] Initial plan From b47113aba1ebeec42680bcbd5cc679de8f3b16cd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 18:24:53 +0000 Subject: [PATCH 2/2] Refactor useSyncQueries.ts to add mutation cache subscription and reduce code duplication Co-authored-by: Rezrazi <2086576+Rezrazi@users.noreply.github.com> --- .../useSyncQueries.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/react-query-external-sync/useSyncQueries.ts b/src/react-query-external-sync/useSyncQueries.ts index 6e0e21a..be187a4 100644 --- a/src/react-query-external-sync/useSyncQueries.ts +++ b/src/react-query-external-sync/useSyncQueries.ts @@ -413,9 +413,9 @@ export function useSyncQueriesExternal({ ); // ========================================================== - // Subscribe to query changes and sync to dashboard + // Reusable function to sync state changes to dashboard // ========================================================== - const unsubscribe = queryClient.getQueryCache().subscribe(() => { + const syncStateToDesktop = () => { if (!deviceId) { log(`${logPrefix} No persistent device ID found`, enableLogs, "warn"); return; @@ -433,7 +433,17 @@ export function useSyncQueriesExternal({ // Send message to dashboard socket.emit("query-sync", syncMessage); - }); + }; + + // ========================================================== + // Subscribe to query cache changes and sync to dashboard + // ========================================================== + const queryCacheSubscription = queryClient.getQueryCache().subscribe(syncStateToDesktop); + + // ========================================================== + // Subscribe to mutation cache changes and sync to dashboard + // ========================================================== + const mutationCacheSubscription = queryClient.getMutationCache().subscribe(syncStateToDesktop); // ========================================================== // Cleanup function to unsubscribe from all events @@ -443,7 +453,8 @@ export function useSyncQueriesExternal({ queryActionSubscription?.off(); initialStateSubscription?.off(); onlineManagerSubscription?.off(); - unsubscribe(); + queryCacheSubscription(); + mutationCacheSubscription(); }; }, [queryClient, socket, deviceName, isConnected, deviceId, enableLogs]);