fix : 무한 스크롤 중복·누락 수정 (안 읽은 글은 id 커서 방식으로 조회)
SpecialSource Frontend (React) CD / deploy (push) Successful in 13s

- 스크롤 중 새 글이 스크랩되거나 글을 읽어 순서가 밀리면 다음 페이지에 중복·누락이 생기던 문제
- 안 읽은 글: before(마지막 글 id) 커서로 다음 페이지 조회 (백엔드 before 파라미터 필요)
- 읽은 글: 페이지 번호 방식 유지, 이미 받은 글은 걸러냄
- 요청 사이 목록이 바뀌었으면 늦게 온 응답은 버림

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-25 15:44:05 +09:00
1 parent d94aaa6f0a
commit cbc41ef444
3 files changed
+26 -12

No files matched your search

+11 -5
View File
@@ -31,13 +31,19 @@ function findMenu(raw: string): MenuItem | undefined {
}
/** 클릭/키보드 입력이 모두 거치는 단일 명령 처리기 (순수 함수 → useReducer reducer로 사용) */
export function execute(prev: BbsState, input: string | Nav | Partial<BbsState> | { more: Feed }): BbsState {
export function execute(
prev: BbsState,
input: string | Nav | Partial<BbsState> | { more: Feed; after: Feed },
): BbsState {
if (typeof input !== "string" && "more" in input) {
// 무한 스크롤 다음 페이지: 지금 목록의 바로 다음 페이지일 때만 이어 붙임 (그 사이 탭을 바꿨거나 새로고침했으면 버림)
const { more } = input;
// 무한 스크롤 다음 페이지: 요청할 때의 목록이 지금도 그대로일 때만 이어 붙임 (그 사이 탭을 바꿨거나 새로고침했으면 버림)
const { more, after } = input;
const f = prev.feed;
if (!f || f.kind !== more.kind || f.board !== more.board || more.page !== f.page + 1) return prev;
return { ...prev, feed: { ...more, posts: [...f.posts, ...more.posts] } };
if (f !== after) return prev;
// 읽은 글 목록은 페이지 번호 방식이라, 그 사이 순서가 밀리면 받은 글이 또 나올 수 있음 → 이미 받은 글은 버림
const seen = new Set(f.posts.map((p) => p.id));
const posts = [...f.posts, ...more.posts.filter((p) => !seen.has(p.id))];
return { ...prev, feed: { ...more, total: f.total, posts } }; // 건수는 첫 페이지 기준 유지
}
if (typeof input !== "string") return { ...prev, error: null, ...input }; // 화면 복원, 로그인, 목록 도착, 오류
const raw = input.trim();