[복덕방/Hotfix] Naver Maps SDK destroy 시 TypeError 수정#1221
Conversation
Walkthrough
Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
useNaverMap 훅의 effect를 생성/파괴용과 좌표 업데이트용으로 분리하고, destroy() 호출을 try-catch로 감싸 SDK 내부 _clearSwipe 타이밍 이슈 방어
b603044 to
735d557
Compare
|
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/Room/RoomPage/hooks/useNaverMap.ts (1)
6-8:⚠️ Potential issue | 🟠 Major
try/catch는 비동기 SDK 에러를 처리하지 못할 수 있습니다.PR 설명처럼 Naver Maps의
destroy()가 내부적으로setTimeout을 통해_clearSwipe를 실행한다면, 그 콜백에서 발생하는 예외는 Line 23-25의catch블록에 포착되지 않습니다. JavaScript의try/catch는 동기 코드만 처리하며, 비동기 콜백의 예외는 다른 실행 컨텍스트에서 발생하기 때문입니다.추가로 현재 코드는
useEffect의 cleanup 함수를 사용하는데, React에서useEffectcleanup은 DOM이 제거된 이후에 실행됩니다. 만약 SDK가 cleanup 중에 이미 제거된 DOM 요소에 접근한다면 같은 문제가 반복될 수 있습니다.권장 사항:
useLayoutEffect로 변경하여 cleanup을 DOM 제거 이전에 실행하거나- Naver Maps API 문서를 확인하여
destroy()호출 후 SDK 정리 작업이 완료될 때까지의 시간을 파악하고, 필요시 컨테이너 DOM을 제거 전까지 유지하세요.현재 try/catch만으로는 근본적인 해결책이 아닐 가능성이 있습니다.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Room/RoomPage/hooks/useNaverMap.ts` around lines 6 - 8, The current useNaverMap effect uses try/catch around synchronous calls but that won't catch exceptions thrown asynchronously by the Naver Maps SDK (e.g., inside destroy()'s setTimeout or _clearSwipe), and React's useEffect cleanup runs after DOM removal; change the effect to useLayoutEffect (replace useEffect with useLayoutEffect in useNaverMap) so cleanup runs before DOM removal, and ensure destroy() is invoked from that layout-effect cleanup; additionally, verify or delay DOM removal until the SDK finishes its async cleanup (consult Naver Maps docs) rather than relying solely on try/catch around naver.maps.Map.destroy to prevent asynchronous exceptions from accessing removed DOM.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/Room/RoomPage/hooks/useNaverMap.ts`:
- Around line 10-20: The map is being recreated whenever latitude/longitude
change because the map-creation effect depends on them; change the
creation/cleanup of the map (the code that constructs mapInstance, assigns
mapRef.current and calls mapInstance.destroy()) to only depend on isLoaded so
creation/destruction happens only when isLoaded toggles, not on coordinate
updates; to satisfy exhaustive-deps, capture the initial latitude/longitude in
refs (e.g., initialLatRef/initialLngRef) and use those refs when constructing
the Map instead of latitude/longitude in the dependency array; keep a separate
effect that watches latitude and longitude and calls
mapRef.current.setCenter(new naver.maps.LatLng(latitude, longitude)) (no
destroy/recreate) so center updates don't trigger map reconstruction.
---
Outside diff comments:
In `@src/components/Room/RoomPage/hooks/useNaverMap.ts`:
- Around line 6-8: The current useNaverMap effect uses try/catch around
synchronous calls but that won't catch exceptions thrown asynchronously by the
Naver Maps SDK (e.g., inside destroy()'s setTimeout or _clearSwipe), and React's
useEffect cleanup runs after DOM removal; change the effect to useLayoutEffect
(replace useEffect with useLayoutEffect in useNaverMap) so cleanup runs before
DOM removal, and ensure destroy() is invoked from that layout-effect cleanup;
additionally, verify or delay DOM removal until the SDK finishes its async
cleanup (consult Naver Maps docs) rather than relying solely on try/catch around
naver.maps.Map.destroy to prevent asynchronous exceptions from accessing removed
DOM.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f283e367-86d4-41f2-af6c-8709b884d190
📒 Files selected for processing (1)
src/components/Room/RoomPage/hooks/useNaverMap.ts
Summary
useNaverMap훅의 effect를 생성/파괴용과 좌표 업데이트용으로 분리destroy()호출을try-catch로 감싸 Naver Maps SDK 내부_clearSwipe타이밍 이슈 방어관련 이슈
원인
if (!mapRef.current)블록 안에서만 반환되어 항상 보장되지 않음destroy()내부에서setTimeout으로 예약된_clearSwipe가 DOM 제거 후 실행되면서releaseCapture접근 시 TypeError 발생Summary by CodeRabbit
버그 수정
개선사항