Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(timeline): reset state when reconnecting to fetch fresh data

Louis Beaumont19c93660063f
diff --git a/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
index f339eef7a..846a25fb3 100644
--- a/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
@@ -110,6 +110,24 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({
},
connectWebSocket: () => {
+ // Close existing websocket if any
+ const existingWs = get().websocket;
+ if (existingWs && existingWs.readyState === WebSocket.OPEN) {
+ existingWs.close();
+ }
+
+ // Reset state for fresh data when reconnecting
+ set({
+ frames: [],
+ frameTimestamps: new Set<string>(),
+ sentRequests: new Set<string>(),
+ isLoading: true,
+ loadingProgress: { loaded: 0, isStreaming: false },
+ error: null,
+ message: null,
+ });
+ frameBuffer = [];
+
const ws = new WebSocket("ws://localhost:3030/stream/frames");
ws.onopen = () => {