Fix: Improve preview loading and error handling

This commit is contained in:
gpt-engineer-app[bot]
2025-10-11 14:45:22 +00:00
parent 1e30dedca2
commit 092337ee9e
4 changed files with 123 additions and 30 deletions

View File

@@ -24,27 +24,36 @@ export function useLocationAutoDetect() {
// Only run auto-detection after preferences have loaded
if (loading) return;
// Check if localStorage is available
if (!isLocalStorageAvailable()) {
console.warn('localStorage is not available, skipping location auto-detection');
return;
}
// Check if we've already attempted detection
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
if (preferences.auto_detect && !hasAttemptedDetection) {
autoDetectPreferences().then(() => {
if (isLocalStorageAvailable()) {
localStorage.setItem('location_detection_attempted', 'true');
// Defer auto-detection to not block initial render
const timeoutId = setTimeout(() => {
try {
// Check if localStorage is available
if (!isLocalStorageAvailable()) {
console.warn('localStorage is not available, skipping location auto-detection');
return;
}
}).catch((error) => {
console.error('❌ Failed to auto-detect location:', error);
if (isLocalStorageAvailable()) {
localStorage.setItem('location_detection_attempted', 'true');
// Check if we've already attempted detection
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
if (preferences.auto_detect && !hasAttemptedDetection) {
autoDetectPreferences().then(() => {
if (isLocalStorageAvailable()) {
localStorage.setItem('location_detection_attempted', 'true');
}
}).catch((error) => {
console.error('❌ Failed to auto-detect location:', error);
if (isLocalStorageAvailable()) {
localStorage.setItem('location_detection_attempted', 'true');
}
});
}
});
}
}, [user, loading, preferences.auto_detect]);
} catch (error) {
console.error('❌ Error in location auto-detection:', error);
}
}, 1000); // Defer by 1 second to allow app to render first
return () => clearTimeout(timeoutId);
}, [user, loading, preferences.auto_detect, autoDetectPreferences]);
}