From 5d9e142596e30cfd6c32d7b42031ed91b8840639 Mon Sep 17 00:00:00 2001 From: SyedaAnshrahGillani Date: Wed, 4 Mar 2026 08:01:25 +0500 Subject: [PATCH 1/2] refactor: optimize polling and improve optimistic update stability (#753) Co-authored-by: Syeda Anshrah Gillani --- packages/lib/queries.ts | 43 +++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/lib/queries.ts b/packages/lib/queries.ts index 411bdce6f..7b6212214 100644 --- a/packages/lib/queries.ts +++ b/packages/lib/queries.ts @@ -47,8 +47,8 @@ export const fetchSubscriptionStatus = ( return statusMap }, queryKey: ["subscription-status"], - refetchInterval: 5000, // Refetch every 5 seconds - staleTime: 4000, // Consider data stale after 4 seconds + refetchInterval: 60 * 1000, // Refetch every 1 minute + staleTime: 55 * 1000, // Consider data stale after 55 seconds enabled: isEnabled, }) @@ -132,18 +132,41 @@ export const useDeleteDocument = (selectedProject: string) => { ["documents-with-memories", selectedProject], (old: unknown) => { if (!old || typeof old !== "object") return old - const typedOld = old as { - pages?: Array<{ documents?: DocumentWithMemories[] }> + + // Handle Infinite Query structure (TanStack Query v5 uses 'pages') + if ( + "pages" in old && + Array.isArray((old as Record).pages) + ) { + const typedOld = old as { + pages: Array<{ documents?: DocumentWithMemories[] }> + } + return { + ...typedOld, + pages: typedOld.pages.map((page) => ({ + ...page, + documents: page.documents?.filter( + (doc: DocumentWithMemories) => doc.id !== documentId, + ), + })), + } } - return { - ...typedOld, - pages: typedOld.pages?.map((page) => ({ - ...page, - documents: page.documents?.filter( + + // Handle Standard Query structure + if ( + "documents" in old && + Array.isArray((old as Record).documents) + ) { + const typedOld = old as { documents: DocumentWithMemories[] } + return { + ...typedOld, + documents: typedOld.documents.filter( (doc: DocumentWithMemories) => doc.id !== documentId, ), - })), + } } + + return old }, ) From 5e5d446659549e7f8e2b4e03f5cb9947ceb87312 Mon Sep 17 00:00:00 2001 From: Soumya Snigdha Kundu Date: Wed, 4 Mar 2026 03:02:58 +0000 Subject: [PATCH 2/2] fix: remove dead IS_DEV constant and no-op ternary in memories-grid (#760) --- apps/web/components/memories-grid.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index 6a621b4b3..5163814a5 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -62,8 +62,7 @@ type OgData = { image?: string } -const IS_DEV = process.env.NODE_ENV === "development" -const PAGE_SIZE = IS_DEV ? 100 : 100 +const PAGE_SIZE = 100 const MAX_TOTAL = 1000 // Discriminated union for masonry items