From 7ddbfe6dd9b92536ab5110a9dded7c8d0ff768ec Mon Sep 17 00:00:00 2001 From: ved015 Date: Mon, 6 Apr 2026 13:59:02 +0530 Subject: [PATCH] apply sentry suggestion --- apps/web/components/memories-grid.tsx | 33 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index a89f6fa4..16162718 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -716,7 +716,6 @@ const DocumentCard = memo( const [rotation, setRotation] = useState({ rotateX: 0, rotateY: 0 }) const cardRef = useRef(null) const [ogData, setOgData] = useState(null) - const [isLoadingOg, setIsLoadingOg] = useState(false) const ogImage = (document as DocumentWithMemories & { ogImage?: string }) .ogImage @@ -733,15 +732,31 @@ const DocumentCard = memo( const hideURL = document.url?.includes("docs.googleapis.com") useEffect(() => { - if (needsOgData && !ogData && !isLoadingOg && document.url) { - setIsLoadingOg(true) - fetchOgData(document.url) - .then((data) => { - setOgData(data || {}) - }) - .finally(() => setIsLoadingOg(false)) + if (!needsOgData || ogData || !document.url) return + + let timeoutId: ReturnType + let mounted = true + + const attemptFetch = () => { + if (!mounted || !document.url) return + fetchOgData(document.url).then((data) => { + if (!mounted) return + if (data) { + setOgData(data) + } else { + // Retry when the global TTL expires + timeoutId = setTimeout(attemptFetch, 30_000) + } + }) } - }, [needsOgData, ogData, isLoadingOg, document.url]) + + attemptFetch() + + return () => { + mounted = false + clearTimeout(timeoutId) + } + }, [needsOgData, ogData, document.url]) useEffect(() => { if (isSelectionMode) setRotation({ rotateX: 0, rotateY: 0 })