Skip to content

Commit 5660be0

Browse files
committed
[복덕방/Hotfix] Naver Maps SDK destroy 시 TypeError 수정 (#1220)
useNaverMap 훅의 effect를 생성/파괴용과 좌표 업데이트용으로 분리하고, destroy() 호출을 try-catch로 감싸 SDK 내부 _clearSwipe 타이밍 이슈 방어
1 parent 44eeab9 commit 5660be0

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

src/components/Room/RoomPage/hooks/useNaverMap.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ function useNaverMap(latitude: number, longitude: number, isLoaded: boolean = tr
77
if (!isLoaded || !window.naver?.maps) return;
88
if (!document.getElementById('map')) return;
99

10-
if (!mapRef.current) {
11-
const mapInstance = new window.naver.maps.Map('map', {
12-
center: new window.naver.maps.LatLng(latitude, longitude),
13-
maxZoom: 20,
14-
minZoom: 15,
15-
logoControl: false,
16-
zoomControl: true,
17-
scrollWheel: false,
18-
draggable: true,
19-
zoomControlOptions: { position: window.naver.maps.Position.TOP_LEFT },
20-
});
21-
mapRef.current = mapInstance;
22-
23-
return () => {
10+
const mapInstance = new window.naver.maps.Map('map', {
11+
center: new window.naver.maps.LatLng(latitude, longitude),
12+
maxZoom: 20,
13+
minZoom: 15,
14+
logoControl: false,
15+
zoomControl: true,
16+
scrollWheel: false,
17+
draggable: true,
18+
zoomControlOptions: { position: window.naver.maps.Position.TOP_LEFT },
19+
});
20+
mapRef.current = mapInstance;
21+
22+
return () => {
23+
try {
2424
mapInstance.destroy();
25-
mapRef.current = null;
26-
};
27-
}
28-
29-
mapRef.current.setCenter(new window.naver.maps.LatLng(latitude, longitude));
25+
} catch {
26+
// Naver Maps SDK 내부 _clearSwipe 타이밍 이슈 방어
27+
}
28+
mapRef.current = null;
29+
};
3030
}, [isLoaded, latitude, longitude]);
3131

32+
useEffect(() => {
33+
if (mapRef.current) {
34+
mapRef.current.setCenter(new window.naver.maps.LatLng(latitude, longitude));
35+
}
36+
}, [latitude, longitude]);
37+
3238
const getMap = () => mapRef.current;
3339

3440
return { getMap };

0 commit comments

Comments
 (0)