WebSocket을 통해 notification
및 error
메시지를 구독할 때, 재연결 시 동일한 구독이 여러 번 등록되는 문제가 발생했습니다. 이는 다음과 같은 현상으로 나타났습니다:
pendingSubscriptions
배열에 동일한 구독 항목이 여러 개 삽입됨pendingSubscriptions
배열이 초기화되지 않아 동일한 구독이 계속해서 추가됨.pendingSubscriptions
배열에서 type
과 identifier
가 동일한 구독을 중복 삽입하는 문제 발생.pendingSubscriptions
배열에 새로운 구독을 추가하기 전에, 이미 동일한 구독이 존재하는지 확인하는 로직을 추가하여 중복 구독을 방지함.
addPendingSubscription: (subscription: PendingSubscription) => {
set((state) => {
// type과 identifier가 동일한 구독이 이미 존재하는지 확인
const isDuplicate = state.pendingSubscriptions.some(
(existing) =>
existing.type === subscription.type &&
existing.identifier === subscription.identifier
);
// 이미 존재하면 추가하지 않음
if (isDuplicate) {
return state;
}
// 중복되지 않는 경우에만 새로운 구독 추가
return {
pendingSubscriptions: [...state.pendingSubscriptions, subscription],
};
});
},
pendingSubscriptions
배열을 확인하여 이미 같은 type
과 identifier
를 가진 구독이 존재하면 추가하지 않음