[Refactor] SSE 훅을 Provider로 통합, unReadCount 전역상태에서 제거#394
Conversation
|
@coderabbitai review |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
워크스루알림 시스템을 React Context 기반 후크에서 Zustand 저장소 및 SSE 컴포넌트 기반 아키텍처로 재구성합니다. NotificationProvider를 SSEProvider로 교체하고, 관련 후크 및 쿼리 무효화 로직을 업데이트하여 저장소 기반 상태 관리로 전환합니다. 변경사항
예상 코드 리뷰 난이도🎯 4 (복잡) | ⏱️ ~50분 관련된 가능성 있는 PR들
제안된 레이블
제안된 리뷰어
시 🐰
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
📊 Coverage Report
📉 #394을 main에 병합하면 coverage가 Coverage 요약@@ Coverage Diff @@
## main #394 +/- ##
===========================================
- Coverage 35.69% 35.36% -0.33%
===========================================
Files 267 264 -3
Lines 12136 12104 -32
Branches 469 474 +5
===========================================
- Hits 4332 4280 -52
+ Misses 7804 7824 +20 영향받은 파일
|
🎭 Playwright Report✨ E2E Test가 성공적으로 완료되었습니다. Test 요약 내용을 확인해주세요.
📊 Test Summary
📜 Test Details✅ Passed Tests (3)
|
🎨 Storybook Report✅ 변경 사항이 없습니다 모든 Story가 이전 빌드와 동일합니다.
|
🚀 PR Preview Report✨ Build가 성공적으로 완료되었습니다. Preview에서 변경사항을 확인하세요.
|
✅ Actions performedReview triggered.
|
|
@coderabbitai 리뷰 내용 없나요? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 4809 🏁 Script executed: Length of output: 1164 🏁 Script executed: Length of output: 1477 🏁 Script executed: Length of output: 74 🏁 Script executed: Length of output: 101 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 109 🏁 Script executed: Length of output: 318 🏁 Script executed: Length of output: 66 🏁 Script executed: Length of output: 641 🏁 Script executed: Length of output: 72 🏁 Script executed: Length of output: 5178 🏁 Script executed: Length of output: 93 🏁 Script executed: Length of output: 300 🏁 Script executed: Length of output: 27 🏁 Script executed: Length of output: 579 🏁 Script executed: Length of output: 5573 🏁 Script executed: Length of output: 1078 🏁 Script executed: Length of output: 2577
전반적으로 SSE 로직을 하나의 Provider로 통합하고 서버 상태와 클라이언트 상태를 명확하게 분리한 점은 좋은 리팩토링입니다. 다만 몇 가지 개선할 부분이 있습니다: 주요 이슈1. 의존성 배열 문제 (src/providers/provider-sse/index.tsx, Line 158)}, [receivedData, setReceivedData]);Zustand의 setter 함수( 수정 제안: }, [receivedData]);2. 함수 정의 위치 및 메모이제이션
수정 제안: const setupSSEConnection = useCallback((token: string) => {
// ... existing code
}, [setReceivedData, setHasNewNotification]);
const reconnect = useCallback(async () => {
// ... existing code
}, [setupSSEConnection]);
// 또는 connect/disconnect도 useCallback으로 감싸거나
// 모든 로직을 useEffect 내부로 이동3. 순환 참조 패턴Line 38에서 store의 제안:
4. 하드코딩된 타임아웃Line 155의 3초 timeout이 하드코딩되어 있습니다. 상수로 분리하는 것이 좋습니다: const NOTIFICATION_DISPLAY_DURATION = 3000;
const timer = setTimeout(() => {
setReceivedData(null);
setHasNewNotification(false);
}, NOTIFICATION_DISPLAY_DURATION);긍정적인 부분✅ 서버 상태(unReadCount)와 클라이언트 상태(hasNewNotification)의 명확한 분리 이러한 개선사항들을 반영하면 더 견고한 코드가 될 것 같습니다. 추가 질문 있으시면 말씀해주세요! |
📝 변경 사항
SSEProvider 통합 및 NotificationProvider 제거 변경사항
커밋 히스토리
c200170e9c48ec1. useSSEConnect + useSSEEvent → SSEProvider 통합
기존에 분리되어 있던
useSSEConnect(연결 관리)와useSSEEvent(이벤트 처리) 두 훅을SSEProvider로 통합.NotificationProvider를 완전히 대체.통합 이유
커스텀 훅은 본질적으로 재사용을 위한 패턴이지만,
useSSEConnect와useSSEEvent는 앱 전체에서 단 한 번만 실행되어야 하며 재사용되면 안 되는 로직. 재사용 목적이 아닌 로직을 커스텀 훅으로 관리하는 것은 패턴에 위반되므로, Provider 내부에 종속시켜 단일 실행을 보장하도록 변경.Before
After
SSEProvider 내부 구조
2. NotificationProvider 삭제 - unReadCount는 React Query 훅 직접 호출
NotificationProvider(Context 기반)를 완전히 삭제. 기존에 Context를 통해 전달하던unReadCount는 필요한 컴포넌트에서useGetNotificationUnreadCount훅을 직접 호출하도록 변경.변경 이유
unReadCount는 서버 상태이므로 전역 상태(Context/Store)에 저장하지 않고, React Query 훅을 직접 호출하여 관리하는 것이 상태 관리 원칙에 부합.unReadCountuseGetNotificationUnreadCount직접 호출)receivedDatauseNotificationStore)hasNewNotificationuseNotificationStore)컴포넌트별 변경
cow-bell(헤더 알림 벨)useNotification()useGetNotificationUnreadCount()+useNotificationStore()notification-headeruseNotification()useGetNotificationUnreadCount()3. providers.tsx Provider 교체
src/app/providers.tsx에서NotificationProvider→SSEProvider로 교체.삭제된 파일 목록
src/hooks/use-sse/index.tssrc/hooks/use-sse/use-sse-event/index.tssrc/providers/provider-notification/index.tsx변경된 파일 목록
src/hooks/use-sse/use-sse-connect/index.ts→src/providers/provider-sse/index.tsxsrc/providers/index.tssrc/app/providers.tsxsrc/components/layout/header/cow-bell/index.tsxsrc/components/pages/notification/notification-header/index.tsx🔗 관련 이슈
Closes #
🧪 테스트 방법
📸 스크린샷 (선택)
📋 체크리스트
💬 추가 코멘트
CodeRabbit Review는 자동으로 실행되지 않습니다.
Review를 실행하려면 comment에 아래와 같이 작성해주세요
Summary by CodeRabbit
릴리스 노트