-
Notifications
You must be signed in to change notification settings - Fork 0
실시간 알림(SSE) 버그 수정 ( issue #310 ) #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
4bc193d
f2dd243
e71f9e3
f8bea52
08969a5
da0a3f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import useNotification from '../../../hooks/user/useNotification'; | ||
|
|
||
| const NotificationInitializer = () => { | ||
| useNotification(); | ||
|
|
||
| return null; | ||
| }; | ||
|
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain초기화 컴포넌트 패턴이 적절합니다. 전역 SSE 연결 초기화를 위한 깔끔한 접근 방식입니다.
🏁 Script executed: #!/bin/bash
# useNotification 훅에서 EventSource cleanup 확인
ast-grep --pattern $'useEffect(() => {
$$$
return () => {
$$$
}
}, $$$)'Length of output: 3614 useNotification 훅 정의 위치와 EventSource 사용 여부를 확인하기 위해 다음 스크립트를 실행해주세요: 🏁 Script executed: #!/bin/bash
# useNotification 훅이 정의된 파일 찾기
rg "useNotification" -n src
# EventSource 인스턴스 생성 및 cleanup 확인
rg "EventSource" -n srcLength of output: 1094 useNotification 훅의 🏁 Script executed: #!/bin/bash
# useNotification.ts의 useEffect 블록 및 EventSource close 호출 여부 확인
rg "useEffect" -n src/hooks/user/useNotification.ts -A20 -B5Length of output: 1413 useNotification 훅의 전체 cleanup 로직을 확인하기 위해 아래 스크립트를 실행해주세요: 🏁 Script executed: #!/bin/bash
# useNotification.ts의 return cleanup 블록 확인
rg "return \\(\\) =>" -n src/hooks/user/useNotification.ts -A20 -B5Length of output: 67 useNotification 훅의 useEffect 전체 블록(cleanup 반환 함수 포함)을 확인하기 위해 아래 스크립트를 실행해주세요: 🏁 Script executed: #!/bin/bash
# useNotification.ts의 useEffect 블록 전체 출력 (cleanup 포함)
rg "useEffect" -n src/hooks/user/useNotification.ts -A150 -B5Length of output: 2278 useNotification 훅에 SSE 연결 정리(cleanup) 로직 추가가 필요합니다. 현재 다음 부분에 cleanup 반환 함수를 추가해주세요.
예시 수정안: useEffect(() => {
if (!userId) {
if (eventSourceRef.current) {
eventSourceRef.current.close();
eventSourceRef.current = null;
}
return;
}
if (eventSourceRef.current) {
return;
} else {
const eventSource = new EventSource(/* … */);
eventSourceRef.current = eventSource;
// 이벤트 핸들러 등록…
}
+ // 컴포넌트 언마운트 또는 userId/queryClient 변경 시 SSE 연결 닫기
+ return () => {
+ if (eventSourceRef.current) {
+ eventSourceRef.current.close();
+ eventSourceRef.current = null;
+ }
+ };
}, [queryClient, userId]);위 변경으로 언마운트 시점 및 의존성 변경 시 EventSource가 정상적으로 종료됩니다.
🤖 Prompt for AI Agents |
||
|
|
||
| export default NotificationInitializer; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { ReactNode, useState } from 'react'; | ||
| import { AlarmLive } from '../../../models/alarm'; | ||
| import { SseContext } from '../../../context/SseContext'; | ||
|
|
||
| export const NotificationProvider = ({ children }: { children: ReactNode }) => { | ||
| const [signalData, setSignalData] = useState<AlarmLive | null>(null); | ||
|
|
||
| const clearSignal = () => setSignalData(null); | ||
| const setSignal = (data: AlarmLive | null) => setSignalData(data); | ||
|
|
||
| return ( | ||
| <SseContext.Provider value={{ signalData, clearSignal, setSignal }}> | ||
| {children} | ||
| </SseContext.Provider> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { createContext, useContext } from 'react'; | ||
| import { AlarmLive } from '../models/alarm'; | ||
|
|
||
| export interface SseContextProps { | ||
| signalData: AlarmLive | null; | ||
| clearSignal: () => void; | ||
| setSignal: (data: AlarmLive | null) => void; | ||
| } | ||
|
|
||
| export const SseContext = createContext<SseContextProps>({ | ||
| signalData: null, | ||
| clearSignal: () => {}, | ||
| setSignal: () => {}, | ||
| }); | ||
|
|
||
| export const useNotificationContext = () => useContext(SseContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
프로덕션에서 자동 테스트 알림 호출 확인 필요
헤더 컴포넌트가 마운트될 때마다
testLiveAlarm()이 자동으로 호출됩니다. 이는 프로덕션 환경에서 의도하지 않은 알림을 발송할 수 있습니다.개발/테스트 환경에서만 실행되도록 제한하거나, 다른 트리거 방식을 고려해보세요.
다음 스크립트로 다른 컴포넌트에서도 비슷한 패턴이 있는지 확인해보겠습니다:
🏁 Script executed:
Length of output: 1278
❗ 프로덕션 환경 자동 테스트 알람 호출 차단 필요
헤더 컴포넌트가 마운트될 때마다
testLiveAlarm()을 무조건 호출하고 있어, 프로덕션 배포 시 의도치 않게 알림이 발송될 수 있습니다. 개발/테스트 환경에서만 동작하도록 환경 변수를 체크하거나 별도 플래그로 제어하세요.수정 위치:
제안 변경:
useEffect(() => { - testLiveAlarm(); + if (process.env.NODE_ENV === 'development') { + testLiveAlarm(); + } }, []);📝 Committable suggestion
🤖 Prompt for AI Agents