From d8e21b8cdfc533102e2f5463426d526a1e52ff25 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Mon, 15 Dec 2025 15:44:34 -0500 Subject: [PATCH] Fix location sharing: increase timeout, prevent auto-start cycling, graceful error handling --- src/app/room/[slug]/page.tsx | 11 +++++++---- src/hooks/useLocationSharing.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/room/[slug]/page.tsx b/src/app/room/[slug]/page.tsx index c014782..66e6dfc 100644 --- a/src/app/room/[slug]/page.tsx +++ b/src/app/room/[slug]/page.tsx @@ -93,13 +93,16 @@ export default function RoomPage() { highAccuracy: true, }); - // Auto-start location sharing when connected + // Auto-start location sharing when connected (only once) + const hasAutoStartedRef = useRef(false); + useEffect(() => { - if (isConnected && currentUser && !isSharing) { - console.log('Auto-starting location sharing'); + if (isConnected && currentUser && !hasAutoStartedRef.current) { + console.log('Auto-starting location sharing (first time)'); + hasAutoStartedRef.current = true; startSharing(); } - }, [isConnected, currentUser, isSharing, startSharing]); + }, [isConnected, currentUser, startSharing]); // Track if we've centered on user's location yet const hasCenteredRef = useRef(false); diff --git a/src/hooks/useLocationSharing.ts b/src/hooks/useLocationSharing.ts index 8436964..193a3d7 100644 --- a/src/hooks/useLocationSharing.ts +++ b/src/hooks/useLocationSharing.ts @@ -8,9 +8,9 @@ interface UseLocationSharingOptions { updateInterval?: number; /** Enable high accuracy mode (uses more battery) */ highAccuracy?: boolean; - /** Maximum age of cached position in ms (default: 10000) */ + /** Maximum age of cached position in ms (default: 30000) */ maxAge?: number; - /** Timeout for position request in ms (default: 10000) */ + /** Timeout for position request in ms (default: 30000) */ timeout?: number; } @@ -38,8 +38,8 @@ export function useLocationSharing( onLocationUpdate, updateInterval = 5000, highAccuracy = true, - maxAge = 10000, - timeout = 10000, + maxAge = 30000, + timeout = 30000, } = options; const [isSharing, setIsSharing] = useState(false); @@ -92,7 +92,9 @@ export function useLocationSharing( const handleError = useCallback((err: GeolocationPositionError) => { setError(err); - console.error('Geolocation error:', err.message); + // Only log as warning, not error - timeouts are common indoors + console.warn('Geolocation warning:', err.message, '(code:', err.code, ')'); + // Don't stop sharing on errors - keep trying }, []); const startSharing = useCallback(() => {