Skip to content

Commit 837fe58

Browse files
committed
fix: resolve build error with style element cleanup
1 parent 18bda49 commit 837fe58

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

web_frontend/src/components/DroneMap.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export function DroneMap() {
7373
const [waypoints, setWaypoints] = useState<Position[]>([]);
7474
const [isFullscreen, setIsFullscreen] = useState(false);
7575
const [isMapReady, setIsMapReady] = useState(false);
76-
const [mapHeight, setMapHeight] = useState('400px');
7776
const [userLocation, setUserLocation] = useState<[number, number] | null>(null);
77+
const styleElementRef = useRef<HTMLStyleElement | null>(null);
7878

7979
// Convert local coordinates to lat/lng (assuming meters from a reference point)
8080
const localToLatLng = (x: number, y: number): [number, number] => {
@@ -144,6 +144,7 @@ export function DroneMap() {
144144

145145
// Add CSS for drone marker
146146
const style = document.createElement('style');
147+
styleElementRef.current = style;
147148
style.textContent = `
148149
.drone-marker {
149150
position: relative;
@@ -250,7 +251,10 @@ export function DroneMap() {
250251
map.current.remove();
251252
map.current = null;
252253
}
253-
style.remove();
254+
if (styleElementRef.current) {
255+
styleElementRef.current.remove();
256+
styleElementRef.current = null;
257+
}
254258
};
255259
}, []); // eslint-disable-line react-hooks/exhaustive-deps
256260

@@ -336,7 +340,7 @@ export function DroneMap() {
336340
}
337341
});
338342
}
339-
}, [dronePosition, isMapReady]);
343+
}, [dronePosition, isMapReady, localToLatLng]);
340344

341345
// Update waypoints on map
342346
useEffect(() => {
@@ -356,7 +360,7 @@ export function DroneMap() {
356360
.setLngLat(localToLatLng(wp.x, wp.y))
357361
.addTo(map.current!);
358362
});
359-
}, [waypoints, isMapReady]);
363+
}, [waypoints, isMapReady, localToLatLng]);
360364

361365
const centerOnDrone = () => {
362366
if (map.current) {

0 commit comments

Comments
 (0)