# task-615.1: InsuWiki TOC 스크롤 스파이 버그 수정

## 증상
- TOC 클릭 → 본문 이동: 정상 동작 ✅
- 본문 스크롤 → TOC 하이라이트 연동: 동작 안 함 ❌

## 현재 구현 위치
- 파일: `/home/jay/projects/insuwiki/nextapp/src/components/TableOfContents.tsx`
- IntersectionObserver: 172~206줄
- 스크롤 컨테이너: `#scroll-container` (DocumentClient.tsx 545줄)

## 디버깅 체크리스트
1. **IntersectionObserver root 확인**: `document.getElementById('scroll-container')`가 observer 생성 시점에 존재하는지
2. **heading ID 일치 확인**: `TableOfContents.tsx`의 `generateId()`와 `DocumentClient.tsx`의 `generateId()`가 동일한 ID를 생성하는지
3. **rootMargin 적합성**: `-140px 0px -70% 0px` — 140px 상단 제외 + 하단 70% 제외 → 감지 영역이 너무 좁지 않은지
4. **visibleIds Set 동작**: entries 처리 로직에서 isIntersecting 판정이 올바른지
5. **isClickedRef 잔류**: 클릭 후 flag가 리셋 안 되어 observer 콜백이 영구 무시되는 경우
6. **useEffect 의존성**: toc 배열이 변경될 때 observer가 재생성되는지
7. **SSR/Hydration**: Next.js SSR에서 document.getElementById 호출 타이밍 문제

## 수정 방향
- 원인을 정확히 파악한 후 최소한의 수정만 적용
- 기존 로직 구조(IntersectionObserver 패턴)는 유지
- 테스트 파일: `__tests__/TableOfContents.test.tsx` (825줄) — 기존 테스트 깨지지 않을 것

## 관련 파일
- `/home/jay/projects/insuwiki/nextapp/src/components/TableOfContents.tsx` (522줄)
- `/home/jay/projects/insuwiki/nextapp/src/app/docs/[id]/DocumentClient.tsx`
- `/home/jay/projects/insuwiki/nextapp/src/components/__tests__/TableOfContents.test.tsx`