Skip to content

refactor(chat): beforeId 기반 무한 스크롤 구현 및 최적화#42

Merged
tnemnorivnelee merged 11 commits into
developfrom
refactor/chat-infinite-scroll-beforeid
Jan 20, 2026
Merged

refactor(chat): beforeId 기반 무한 스크롤 구현 및 최적화#42
tnemnorivnelee merged 11 commits into
developfrom
refactor/chat-infinite-scroll-beforeid

Conversation

@tnemnorivnelee

Copy link
Copy Markdown
Contributor

🔗 관련 이슈

Resolves: #41

📝 작업 내용

  • 채팅 무한 스크롤 구현 (beforeId 기반 페이징):
    • 백엔드 사양에 맞추어 beforeId 파라미터를 사용하는 무한 스크롤 로직을 구현했습니다.
    • Mock 메시지 조회 로직에 beforeId 기반 페이지네이션을 추가하였습니다.
  • TanStack Query useInfiniteQuery 도입:
    • 채팅 목록을 효율적으로 관리하고 페이징 처리를 수행하기 위해 useInfiniteQuery 구조로 전환했습니다.
  • onEndReached 연결 및 최적화:
    • FlatList의 onEndReached를 연결하여 하단 도달 시 추가 데이터를 로드하며, 중복 호출을 방지하도록 처리했습니다.
  • 날짜 구분선(Date Separator) 최적화:
    • 내림차순(desc) 및 무한 스크롤 전제로 날짜 구분선 렌더링 로직을 최적화했습니다.
  • 캐시 업데이트 방식 통일:
    • 메시지 전송 시 useInfiniteQuery 캐시 데이터 구조에 맞춰 캐시를 업데이트하도록 로직을 일원화했습니다.
  • 성능 최적화 (memo, useCallback):
    • React.memouseCallback을 사용하여 리스트 아이템 리렌더링을 최소화하고 스크롤 성능을 개선했습니다.

📷 스크린샷 (UI 작업인 경우)

N/A

💬 리뷰어에게

  • 스크롤 동작 및 캐시 업데이트: 무한 스크롤 시 메시지가 중복되거나 스크롤 위치가 튀지 않는지, 새 메시지 전송 시 캐시가 정상적으로 업데이트되는지 확인 부탁드립니다.
  • 린트 경고: app/(tabs)/_layout.tsx 파일에서 사용되지 않는 ref에 대한 린트 경고가 발생할 수 있습니다. 이는 레이아웃 관련 ref로, 현재 사용되지 않더라도 구조 유지 차원에서 남겨둔 것이니 참고 바랍니다.

✅ 기본 체크리스트

  • 코드가 정상적으로 실행되나요? (yarn start 빌드 에러 없음)
  • (중요) 안드로이드/iOS 시뮬레이터에서 각각 확인했나요?
  • 불필요한 console.log나 주석을 제거했나요?
  • yarn format을 실행하여 코드 스타일을 정렬했나요?
  • yarn lint를 실행하여 린트 에러가 없나요?

🏗️ 구조 체크리스트 (Self-Check)

파일 및 폴더

  • 1개 기능 전용 컴포넌트features/ 안에 두었나요? (❌ shared/ui 금지)
  • 재사용 컴포넌트shared/ui에 두었나요?
  • 파일이 3개 이상일 때만 폴더로 묶었나요? (불필요한 index.ts 방지)

상태 관리 & 네이밍

  • 서버 데이터는 React Query, UI 상태는 Zustand를 사용했나요?
  • Boolean 변수is, has, should로 시작하나요?

🚀 모든 체크리스트를 확인한 후 PR을 생성하세요!

Copilot AI review requested due to automatic review settings January 15, 2026 19:52
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @tnemnorivnelee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 채팅방 메시지 목록에 beforeId 기반의 무한 스크롤 기능을 도입하고 전반적인 성능을 개선합니다. TanStack Query의 useInfiniteQuery를 활용하여 효율적인 데이터 페이징을 구현했으며, FlatListonEndReached 이벤트를 통해 추가 메시지 로딩을 처리합니다. 또한, 날짜 구분선 렌더링 로직을 최적화하고 React.memo, useCallback을 적용하여 UI 리렌더링을 최소화했습니다.

Highlights

  • beforeId 기반 무한 스크롤 구현: 백엔드 사양에 맞춰 beforeId 파라미터를 사용하는 채팅 무한 스크롤 로직을 구현하고, Mock 메시지 조회 로직에 beforeId 기반 페이지네이션을 추가했습니다.
  • TanStack Query useInfiniteQuery 도입: 채팅 목록을 효율적으로 관리하고 페이징 처리를 수행하기 위해 useInfiniteQuery 구조로 전환했습니다.
  • onEndReached 연결 및 최적화: FlatList의 onEndReached를 연결하여 하단 도달 시 추가 데이터를 로드하며, 중복 호출을 방지하도록 처리했습니다.
  • 날짜 구분선(Date Separator) 최적화: 내림차순(desc) 및 무한 스크롤 전제로 날짜 구분선 렌더링 로직을 최적화했습니다.
  • 캐시 업데이트 방식 통일: 메시지 전송 시 useInfiniteQuery 캐시 데이터 구조에 맞춰 캐시를 업데이트하도록 로직을 일원화했습니다.
  • 성능 최적화 (memo, useCallback): React.memouseCallback을 사용하여 리스트 아이템 리렌더링을 최소화하고 스크롤 성능을 개선했습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

beforeId 기반의 무한 스크롤 구현을 위해 useInfiniteQuery를 도입하고, React.memouseCallback을 활용하여 성능을 최적화하는 등 전반적으로 훌륭한 리팩터링입니다. 코드 구조가 개선되었고, 무한 스크롤 관련 로직이 명확하게 구현되었습니다.

다만, useChatRoomMessages 훅에서 성능을 더욱 향상시킬 수 있는 두 가지 지점을 발견했습니다.
첫째, 현재 refetchInterval 설정은 폴링 시마다 모든 페이지의 데이터를 다시 불러와 불필요한 네트워크 요청을 유발할 수 있습니다. 이를 첫 페이지만 리프레시하도록 개선하는 것이 좋습니다.
둘째, 메시지 데이터를 UI에 맞게 변환하는 로직을 useInfiniteQueryselect 옵션으로 옮기면, React Query의 내장 메모이제이션을 활용하여 렌더링 성능을 더욱 최적화할 수 있습니다.

자세한 내용은 아래의 개별 리뷰 코멘트를 참고해주세요.

Comment thread src/features/chat/hooks/useChatRoomMessages.ts
Comment thread src/features/chat/hooks/useChatRoomMessages.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

이 PR은 채팅 메시지 목록에 beforeId 기반 무한 스크롤을 구현하고, TanStack Query의 useInfiniteQuery를 도입하여 효율적인 페이지네이션을 구현합니다.

Changes:

  • useInfiniteQuery로 채팅 메시지 조회 로직 전환 및 beforeId 기반 페이지네이션 구현
  • Mock API에 beforeId/size 파라미터 지원 추가
  • 날짜 구분선 렌더링 로직을 내림차순 데이터에 맞게 최적화
  • React.memouseCallback을 사용한 성능 최적화

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/features/chat/hooks/useChatRoomMessages.ts useQuery를 useInfiniteQuery로 전환하고 중복 제거 로직 추가
src/features/chat/hooks/useSendMessage.ts InfiniteQuery 캐시 구조에 맞춰 메시지 전송 시 캐시 업데이트 로직 수정
src/features/chat/api/mockChatRoomMessages.ts beforeId/size 파라미터를 받는 페이지네이션 로직 추가
src/features/chat/api/chatMessages.ts Mock API 호출을 래핑하는 getChatRoomMessages 함수 추가
src/features/chat/utils/message.ts 날짜 구분선 생성 로직을 내림차순 데이터에 맞게 재작성
src/features/chat/screens/ChatRoomScreen.tsx 무한 스크롤 관련 props를 ChatMessageList에 전달
src/features/chat/components/ChatMessageList.tsx onEndReached 핸들러 추가 및 성능 최적화
src/features/chat/components/ChatMessage.tsx React.memo로 래핑하여 불필요한 리렌더링 방지
src/features/chat/components/ChatRoomItem.tsx React.memo로 래핑하여 불필요한 리렌더링 방지
src/features/chat/components/ChatRoomList.tsx renderItem과 keyExtractor를 useCallback으로 최적화

Comment thread src/features/chat/utils/message.ts
Comment thread src/features/chat/hooks/useSendMessage.ts
Comment thread src/features/chat/hooks/useChatRoomMessages.ts Outdated
Comment thread src/features/chat/components/ChatMessageList.tsx
Comment thread src/features/chat/api/mockChatRoomMessages.ts

@soyeoung1 soyeoung1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@Yeram9286 Yeram9286 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

…nto refactor/chat-infinite-scroll-beforeid
@tnemnorivnelee tnemnorivnelee merged commit 3eaebaa into develop Jan 20, 2026
2 checks passed
@tnemnorivnelee tnemnorivnelee deleted the refactor/chat-infinite-scroll-beforeid branch January 20, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] 채팅 리스트 성능 최적화 및 Orval 전환 대비

4 participants