From 1eaa2f0ac911450af40c7b8a073fc03a432fe401 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 1 Feb 2026 19:00:26 +0000 Subject: [PATCH] Fix auto-retry and time filter pool clearing - Fixed auto-retry: now retries if 0 posts in first 15s after page load - Fixed time filter: now clears post pool when timeHours changes - Removed buggy initialLoadRef-based retry that never triggered Co-Authored-By: Claude Opus 4.5 --- src/components/Map/usePostsEngine.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/Map/usePostsEngine.js b/src/components/Map/usePostsEngine.js index 6fcd682..6085e05 100644 --- a/src/components/Map/usePostsEngine.js +++ b/src/components/Map/usePostsEngine.js @@ -427,6 +427,7 @@ export function usePostsEngine({ const searchResultsRef = useRef(false); const replacePoolRef = useRef(false); const retryRef = useRef({ key: "", count: 0, ts: 0 }); + const pageLoadTimeRef = useRef(Date.now()); const abortControllerRef = useRef(null); const prevContentFilterRef = useRef(contentFilter); const [mapReady, setMapReady] = useState(false); @@ -1250,8 +1251,8 @@ export function usePostsEngine({ if (distKm > Math.max(50, radiusKm * 0.5)) { shouldClearPool = true; } - } else if (forceFetch || last.filterKey !== filterKey) { - // Filter changed or force fetch - clear pool + } else if (forceFetch || last.filterKey !== filterKey || last.timeHours !== timeHours) { + // Filter changed (including time filter) or force fetch - clear pool shouldClearPool = true; } @@ -1388,19 +1389,19 @@ export function usePostsEngine({ setLoadingPosts(false); - // Auto-retry if we got very few posts (network timing issue) - const MIN_EXPECTED_POSTS = 5; + // Auto-retry if we got 0 posts in the first 15 seconds after page load const fetchedCount = Array.isArray(newPosts) ? newPosts.length : 0; - if (fetchedCount < MIN_EXPECTED_POSTS && initialLoadRef.current) { - const retryKey = `retry:${Math.round(lat * 100)}|${Math.round(lng * 100)}`; + const timeSincePageLoad = Date.now() - pageLoadTimeRef.current; + if (fetchedCount === 0 && timeSincePageLoad < 15000) { + const retryKey = `empty:${Math.round(lat * 100)}|${Math.round(lng * 100)}|${filterKey}`; const now = Date.now(); - if (retryRef.current.key !== retryKey || now - retryRef.current.ts > 10000) { + if (retryRef.current.key !== retryKey || now - retryRef.current.ts > 8000) { retryRef.current = { key: retryKey, count: 0, ts: now }; } if (retryRef.current.count < 2) { retryRef.current.count += 1; retryRef.current.ts = now; - console.log(`[usePostsEngine] Low post count (${fetchedCount}), auto-retry #${retryRef.current.count}`); + console.log(`[usePostsEngine] Empty result, auto-retry #${retryRef.current.count} (page load ${Math.round(timeSincePageLoad/1000)}s ago)`); if (delayedFetchRef.current) clearTimeout(delayedFetchRef.current); delayedFetchRef.current = setTimeout(load, 800); }