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.
This commit is contained in:
kempersc 2025-12-07 19:23:12 +01:00
parent 1981dc28ed
commit 12965071be

View file

@ -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),