From ec1d96a77d8649e799ddfca5c8de0c4efbdaa1f6 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Sun, 7 Dec 2025 14:34:35 -0500 Subject: [PATCH] Fix session caching - enable refetch on focus and reconnect --- README.md | 4 ++-- frontend/src/hooks/useOpenCode.ts | 11 +++++++++-- frontend/src/hooks/useSSE.ts | 2 -- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 08d3d4aa..9aa6ed8b 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ A full-stack web application for running [OpenCode](https://github.com/sst/openc ```bash # Clone the repository -git clone https://github.com/yourusername/opencode-webui.git +git clone https://github.com/cstech-dev/opencode-webui.git cd opencode-webui # Start with Docker Compose (single container) @@ -125,7 +125,7 @@ docker exec -it opencode-web sh ```bash # Clone the repository -git clone https://github.com/yourusername/opencode-webui.git +git clone https://github.com/cstech-dev/opencode-webui.git cd opencode-webui # Install dependencies (uses Bun workspaces) diff --git a/frontend/src/hooks/useOpenCode.ts b/frontend/src/hooks/useOpenCode.ts index e3a7d3ad..a7e5a199 100644 --- a/frontend/src/hooks/useOpenCode.ts +++ b/frontend/src/hooks/useOpenCode.ts @@ -28,6 +28,9 @@ export const useSessions = (opcodeUrl: string | null | undefined, directory?: st queryKey: ["opencode", "sessions", opcodeUrl, directory], queryFn: () => client!.listSessions(), enabled: !!client, + refetchOnWindowFocus: true, + refetchOnReconnect: true, + staleTime: 10000, }); }; @@ -38,6 +41,9 @@ export const useSession = (opcodeUrl: string | null | undefined, sessionID: stri queryKey: ["opencode", "session", opcodeUrl, sessionID, directory], queryFn: () => client!.getSession(sessionID!), enabled: !!client && !!sessionID, + refetchOnWindowFocus: true, + refetchOnReconnect: true, + staleTime: 15000, }); }; @@ -49,8 +55,9 @@ export const useMessages = (opcodeUrl: string | null | undefined, sessionID: str queryFn: () => client!.listMessages(sessionID!), enabled: !!client && !!sessionID, refetchOnMount: false, - refetchOnWindowFocus: false, - refetchOnReconnect: false, + refetchOnWindowFocus: true, + refetchOnReconnect: true, + staleTime: 30000, gcTime: 10 * 60 * 1000, placeholderData: (previousData) => previousData, }); diff --git a/frontend/src/hooks/useSSE.ts b/frontend/src/hooks/useSSE.ts index 9b710645..9de76d96 100644 --- a/frontend/src/hooks/useSSE.ts +++ b/frontend/src/hooks/useSSE.ts @@ -333,8 +333,6 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) setIsConnected(true) setError(null) resetReconnectDelay() - queryClient.invalidateQueries({ queryKey: ['opencode', 'sessions', opcodeUrl, directory] }) - queryClient.invalidateQueries({ queryKey: ['opencode', 'messages', opcodeUrl] }) } eventSource.onerror = () => {