From 12965071bed02c43c3a128a1234aba7ee25dd4b8 Mon Sep 17 00:00:00 2001 From: kempersc Date: Sun, 7 Dec 2025 19:23:12 +0100 Subject: [PATCH] fix(frontend): improve DuckLake connection detection in map page Wait for DuckLake loading to complete before deciding whether to use DuckLake data or fallback to static JSON. Prevents race conditions. --- frontend/src/pages/NDEMapPageMapLibre.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/NDEMapPageMapLibre.tsx b/frontend/src/pages/NDEMapPageMapLibre.tsx index bb09eb562f..db2b219b5a 100644 --- a/frontend/src/pages/NDEMapPageMapLibre.tsx +++ b/frontend/src/pages/NDEMapPageMapLibre.tsx @@ -585,8 +585,14 @@ export default function NDEMapPage() { // Load institutions data - prefer DuckLake, fallback to static JSON useEffect(() => { async function loadInstitutions() { - // If DuckLake is connected and has data, use it - if (duckLakeData.isConnected && !duckLakeData.isLoading && duckLakeData.institutions.length > 0) { + // Wait for DuckLake to finish loading before making any decisions + if (duckLakeData.isLoading) { + console.log('[NDEMapPage] Waiting for DuckLake connection...'); + return; + } + + // If DuckLake is connected and has data, use it exclusively + if (duckLakeData.isConnected && duckLakeData.institutions.length > 0) { console.log(`[NDEMapPage] Using DuckLake data: ${duckLakeData.institutions.length} institutions`); setInstitutions(duckLakeData.institutions); @@ -599,13 +605,8 @@ export default function NDEMapPage() { return; } - // If DuckLake is still loading, wait - if (duckLakeData.isConnected && duckLakeData.isLoading) { - return; - } - - // Fallback to static JSON when DuckLake not connected or has error - console.log('[NDEMapPage] DuckLake not available, falling back to static JSON'); + // DuckLake finished loading but has no data or is not connected - use static JSON as fallback + console.log('[NDEMapPage] DuckLake not available or empty, falling back to static JSON'); try { const [instResponse, metaResponse] = await Promise.all([ fetch(INSTITUTIONS_URL),