diff --git a/frontend/src/features/stations/components/StationMap.tsx b/frontend/src/features/stations/components/StationMap.tsx index f01784d..963a4a7 100644 --- a/frontend/src/features/stations/components/StationMap.tsx +++ b/frontend/src/features/stations/components/StationMap.tsx @@ -81,10 +81,23 @@ export const StationMap: React.FC = ({ } }; + // Suppress DOM errors from Google Maps/React conflicts + const handleError = (event: ErrorEvent) => { + if (event.error?.message?.includes('removeChild')) { + // This is a known issue when Google Maps manipulates DOM nodes React is managing + // Suppress the error as it doesn't affect functionality + event.preventDefault(); + console.debug('[StationMap] Suppressed harmless Google Maps DOM error'); + } + }; + + window.addEventListener('error', handleError); + initMap(); // Cleanup: clear markers when component unmounts return () => { + window.removeEventListener('error', handleError); try { markers.current.forEach((marker) => marker.setMap(null)); infoWindows.current.forEach((iw) => iw.close()); diff --git a/frontend/src/features/stations/utils/maps-loader.ts b/frontend/src/features/stations/utils/maps-loader.ts index 937c4d4..5ce20bb 100644 --- a/frontend/src/features/stations/utils/maps-loader.ts +++ b/frontend/src/features/stations/utils/maps-loader.ts @@ -50,9 +50,11 @@ export function loadGoogleMaps(): Promise { }; // Create script tag with callback + // The callback parameter tells Google Maps to call our function when ready + // Using async + callback ensures Google Maps initializes asynchronously const script = document.createElement('script'); script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=${callbackName}&libraries=places`; - script.defer = true; + script.async = true; script.onerror = () => { // Reset promise so retry is possible