refactor(debug): 자체 완결형 DevCoordDebug로 전환 — 프로덕션 번들 완전 제거 보장

- lazy + 동적 import로 DEV에서만 청크 로드
- mapRef 기반 이벤트 등록으로 KoreaMap 코드에 디버그 흔적 없음
- 이전 CoordDebugTool/useCoordDebug 삭제
This commit is contained in:
htlee 2026-03-26 10:30:58 +09:00
부모 8f342f70b7
커밋 364a34ce10
3개의 변경된 파일46개의 추가작업 그리고 43개의 파일을 삭제

파일 보기

@ -201,9 +201,11 @@ const FILTER_I18N_KEY: Record<string, string> = {
cnFishing: 'filters.cnFishingMonitor', cnFishing: 'filters.cnFishingMonitor',
}; };
// [DEBUG] 좌표 디버그 도구 — 프로덕션 빌드에서 tree-shaking 제거 // [DEBUG] 좌표 디버그 — DEV에서만 동적 로드, 프로덕션 번들에서 완전 제거
import { useCoordDebug } from './debug/useCoordDebug'; import { lazy, Suspense } from 'react';
import { CoordDebugOverlay } from './debug/CoordDebugTool'; const DevCoordDebug = import.meta.env.DEV
? lazy(() => import('./debug/DevCoordDebug'))
: null;
export function KoreaMap({ ships, allShips, aircraft, satellites, layers, osintFeed, currentTime, koreaFilters, transshipSuspects, cableWatchSuspects, dokdoWatchSuspects, dokdoAlerts, vesselAnalysis, groupPolygons, hiddenShipCategories, hiddenNationalities, externalFlyTo, onExternalFlyToDone, opsRoute }: Props) { export function KoreaMap({ ships, allShips, aircraft, satellites, layers, osintFeed, currentTime, koreaFilters, transshipSuspects, cableWatchSuspects, dokdoWatchSuspects, dokdoAlerts, vesselAnalysis, groupPolygons, hiddenShipCategories, hiddenNationalities, externalFlyTo, onExternalFlyToDone, opsRoute }: Props) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -216,8 +218,6 @@ export function KoreaMap({ ships, allShips, aircraft, satellites, layers, osintF
const [selectedFleetData, setSelectedFleetData] = useState<SelectedFleetData | null>(null); const [selectedFleetData, setSelectedFleetData] = useState<SelectedFleetData | null>(null);
const { fontScale } = useFontScale(); const { fontScale } = useFontScale();
const [zoomLevel, setZoomLevel] = useState(KOREA_MAP_ZOOM); const [zoomLevel, setZoomLevel] = useState(KOREA_MAP_ZOOM);
// [DEBUG] 좌표 디버그 — DEV에서만 활성화, 프로덕션 빌드에서 tree-shaking 제거
const coordDebug = useCoordDebug(!import.meta.env.DEV);
const zoomRef = useRef(KOREA_MAP_ZOOM); const zoomRef = useRef(KOREA_MAP_ZOOM);
const handleZoom = useCallback((e: { viewState: { zoom: number } }) => { const handleZoom = useCallback((e: { viewState: { zoom: number } }) => {
const z = Math.floor(e.viewState.zoom); const z = Math.floor(e.viewState.zoom);
@ -612,12 +612,11 @@ export function KoreaMap({ ships, allShips, aircraft, satellites, layers, osintF
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}
mapStyle={MAP_STYLE} mapStyle={MAP_STYLE}
onZoom={handleZoom} onZoom={handleZoom}
onClick={coordDebug ? coordDebug.handleMapClick : undefined}
> >
<NavigationControl position="top-right" /> <NavigationControl position="top-right" />
{/* [DEBUG] Ctrl+Click 좌표 표시 — 프로덕션에서 제거 */} {/* [DEBUG] Ctrl+Click 좌표 표시 — 프로덕션 번들에서 완전 제거 */}
{coordDebug && <CoordDebugOverlay points={coordDebug.points} onRemove={coordDebug.removePoint} />} {DevCoordDebug && <Suspense><DevCoordDebug mapRef={mapRef} /></Suspense>}
<Source id="country-labels" type="geojson" data={countryLabelsGeoJSON()}> <Source id="country-labels" type="geojson" data={countryLabelsGeoJSON()}>
<Layer <Layer

파일 보기

@ -1,9 +1,17 @@
/** /**
* [DEBUG TOOL] Ctrl+Click * [DEBUG]
* - (import.meta.env.DEV ) * KoreaMap에서 import하면 .
* import, , .
*/ */
import { useState, useEffect } from 'react';
import { Marker, Popup } from 'react-map-gl/maplibre'; import { Marker, Popup } from 'react-map-gl/maplibre';
import type { CoordPoint } from './useCoordDebug'; import type { MapRef } from 'react-map-gl/maplibre';
interface CoordPoint {
lat: number;
lng: number;
id: number;
}
function toDMS(dd: number, axis: 'lat' | 'lng'): string { function toDMS(dd: number, axis: 'lat' | 'lng'): string {
const dir = axis === 'lat' ? (dd >= 0 ? 'N' : 'S') : (dd >= 0 ? 'E' : 'W'); const dir = axis === 'lat' ? (dd >= 0 ? 'N' : 'S') : (dd >= 0 ? 'E' : 'W');
@ -15,7 +23,33 @@ function toDMS(dd: number, axis: 'lat' | 'lng'): string {
return `${d}°${String(m).padStart(2, '0')}${String(s).padStart(5, '0')}${dir}`; return `${d}°${String(m).padStart(2, '0')}${String(s).padStart(5, '0')}${dir}`;
} }
export function CoordDebugOverlay({ points, onRemove }: { points: CoordPoint[]; onRemove: (id: number) => void }) { interface Props {
mapRef: React.RefObject<MapRef | null>;
}
/**
* .
* mapRef를 click /.
* KoreaMap의 .
*/
export default function DevCoordDebug({ mapRef }: Props) {
const [points, setPoints] = useState<CoordPoint[]>([]);
useEffect(() => {
const map = mapRef.current?.getMap();
if (!map) return;
const handler = (e: maplibregl.MapMouseEvent) => {
if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
e.originalEvent.preventDefault();
setPoints(prev => [...prev, { lat: e.lngLat.lat, lng: e.lngLat.lng, id: Date.now() }]);
}
};
map.on('click', handler);
return () => { map.off('click', handler); };
}, [mapRef]);
return ( return (
<> <>
{points.map(cp => ( {points.map(cp => (
@ -30,7 +64,7 @@ export function CoordDebugOverlay({ points, onRemove }: { points: CoordPoint[];
<Popup <Popup
longitude={cp.lng} longitude={cp.lng}
latitude={cp.lat} latitude={cp.lat}
onClose={() => onRemove(cp.id)} onClose={() => setPoints(prev => prev.filter(p => p.id !== cp.id))}
closeButton={true} closeButton={true}
closeOnClick={false} closeOnClick={false}
anchor="bottom" anchor="bottom"

파일 보기

@ -1,30 +0,0 @@
/**
* [DEBUG] Ctrl+Click
* - disabled=true noop ( dead code )
*/
import { useState, useCallback } from 'react';
import type { MapLayerMouseEvent } from 'react-map-gl/maplibre';
export interface CoordPoint {
lat: number;
lng: number;
id: number;
}
export function useCoordDebug(disabled = false) {
const [points, setPoints] = useState<CoordPoint[]>([]);
const handleMapClick = useCallback((e: MapLayerMouseEvent) => {
if (disabled) return;
if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
e.originalEvent.preventDefault();
setPoints(prev => [...prev, { lat: e.lngLat.lat, lng: e.lngLat.lng, id: Date.now() }]);
}
}, [disabled]);
const removePoint = useCallback((id: number) => {
setPoints(prev => prev.filter(p => p.id !== id));
}, []);
return { points, handleMapClick, removePoint, disabled };
}