Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

[리팩토링] ChatInterface 컴포넌트 구조 개선 및 상태 관리 최적화#149

Merged
haesookimDev merged 8 commits intomainfrom
refactor/chat-interface
Aug 27, 2025
Merged

[리팩토링] ChatInterface 컴포넌트 구조 개선 및 상태 관리 최적화#149
haesookimDev merged 8 commits intomainfrom
refactor/chat-interface

Conversation

@haesookimDev
Copy link
Contributor

설명

  • 기존 ChatInterface 컴포넌트를 복잡한 내부 상태와 로직을 단일 파일에 집중하지 않고, 여러 훅과 하위 컴포넌트로 분리하여 유지보수성과 가독성을 크게 향상시켰습니다.
  • PDF 뷰어 패널, 컬렉션 관리, 입력 처리, 워크플로우 실행 로직 등 각 기능별로 커스텀 훅과 별도 컴포넌트로 분리하여 역할 분담을 명확히 했습니다.
  • 상태 관리를 useReducer 기반의 통합 상태관리 훅(useChatState)으로 전환하여 일관된 상태 업데이트와 액션 디스패치가 가능하도록 구성했습니다.
  • ChatInputChatContainer 컴포넌트를 도입해 입력 UI와 채팅 영역을 별도 컴포넌트로 분리하고 내부 상태 관리를 훅으로 처리하여 재사용성과 테스트 용이성을 개선했습니다.
  • PDF 뷰어 패널 사이즈 조절 및 스크롤 위치 관리도 별도의 훅(useScrollManagement)으로 분리하여 UI 반응성과 사용자 경험을 향상시켰습니다.
  • 실행 중인 워크플로우에 대한 상태 및 에러 관리를 useWorkflowExecution 훅으로 분리하고, 메시지 스트리밍 처리 등 복잡한 워크플로우 로직을 깔끔하게 모듈화했습니다.
  • 컬렉션 선택 및 제거 관련 기능을 useCollectionManagement 훅으로 분리하고 로컬 스토리지 연동을 개선했습니다.
  • 성능 최적화를 위해 React.memo, useMemo, useCallback 등을 적극 활용해 불필요한 렌더링을 방지했습니다.

주요 변경 사항

  • ChatInterface 컴포넌트 리팩토링 및 React.memo 적용
  • 내부 상태 관리를 useReducer 기반 useChatState 훅으로 통합
  • 워크플로우 실행 로직을 useWorkflowExecution 훅으로 분리
  • 컬렉션 관리 로직을 useCollectionManagement 훅으로 분리 및 로컬스토리지 연동 개선
  • 스크롤 위치 저장/복원, 사용자 스크롤 감지 기능을 useScrollManagement 훅으로 분리
  • 채팅 입력 영역을 ChatInput 컴포넌트로 분리하고 입력 상태 및 이벤트 관리 훅(useInputHandling) 도입
  • 채팅 메시지 영역과 컬렉션 표시, 입력 UI 등을 포함하는 ChatContainer 컴포넌트 추가
  • PDF 뷰어 표시 및 패널 크기 조절 기능 통합 및 상태관리 개선
  • 컴포넌트별 Memoization, useMemo, useCallback 등 성능 최적화 반영
  • 관련 타입 및 상태 정의(ChatState, 액션 타입 등) 추가 및 보강
  • refactor/chat-interface 브랜치 내 백업 버전 삭제 및 새 구조에 맞게 재구성

- Introduce new ChatInterface component with enhanced chat features
- Add useCollectionManagement hook for managing selected collections with localStorage sync
- Add useInputHandling hook for input state, IME composition, and auto-resizing textarea
- Add useScrollManagement hook for scroll position, user scroll detection, and smooth scroll-to-bottom
- Add useWorkflowExecution hook to handle workflow execution with streaming and deploy support
- Support dynamic PDF viewer panel with resizable split layout
- Implement attachment menu with collection modal integration
- Preserve scroll position when viewing source documents and during workflow execution
- Improve workflow content loading and error handling with user context support
- Add ChatContainer component with PDF viewer support and panel resizing
- Implement ChatInput component with attachment menu and message handling
- Create CollectionDisplay component to show selected collections
- Develop ChatInterfaceOptimized and ChatInterfaceRefactored2 components for improved chat UI
- Introduce useChatState hook with reducer for centralized chat UI and workflow state management
- Define comprehensive chat state types and actions for UI, panel, PDF viewer, and workflow
- Add related index exports for new components and types
- Enable dynamic PDF viewer loading to avoid SSR issues
- Implement scroll and workflow execution management hooks integration
- Persist panel split state in localStorage for consistent user experience
- Introduce PerformanceTracker class for measuring and aggregating
  performance metrics such as render durations.
- Add hooks useRenderTracker, useMemoryTracker, and useRenderTime to
  track render counts, memory usage, and render durations respectively.
- Create ProfilerWrapper component to integrate React DevTools Profiler
  with custom logging.
- Implement PerformanceBenchmark component to display render counts,
  average render times, and optional memory usage in development mode.
- Add PerformanceComparison component to toggle and compare original
  and optimized component performance during development.
- Replace legacy ChatInterface with a memoized functional component using
  custom hooks for workflow execution, collection, scroll, and chat state
  management.
- Remove redundant state variables and handlers; centralize state via useChatState.
- Modularize logic: separate concerns for workflow execution, input handling,
  and UI state toggling.
- Introduce ChatContainer component to encapsulate chat area and PDF viewer,
  improving layout and performance.
- Simplify additionalParams validation with memoized function.
- Improve scroll handling with useScrollManagement hook for better UX.
- Remove deprecated dynamic imports and ResizablePanel in favor of integrated
  panel management.
- Clean up event handlers and side
Reformatted the "exclude" array in tsconfig.json to a single line
for improved readability and consistency with project style guidelines.
- Add scoped CSS module for ChatInterface container styling
- Introduce useInputHandling hook import (preparation for input logic)
- Replace inline styles with CSS module class for root div
- Fix setInputMessage to update chatContainerRef input properly
- Refactor workflow content loading to handle loading state correctly
  with try-catch-finally and consolidated error handling
- Update useEffect dependencies for scroll management hooks to prevent
  stale closures and ensure consistent scrolling behavior
- Rename ChatInterfaceOptimized to ChatInterface for clarity
- Add hasLoadedExistingChat ref to prevent repeated loading of existing chats
- Modify workflow content loading effect to run only once per workflow content
- Adjust dependencies in useEffect hooks to avoid unnecessary re-renders and reloads
- Capture and clear the current input message before loading existing chat logs
- Pass the captured message to workflowExecution.executeWorkflow to ensure proper execution context
- Clear input message after sending on Enter key press to reset input field
- Add missing dependency to useEffect hooks for consistent behavior and avoid stale closures
@haesookimDev haesookimDev self-assigned this Aug 27, 2025
@haesookimDev haesookimDev merged commit 32811a4 into main Aug 27, 2025
4 checks passed
@haesookimDev haesookimDev deleted the refactor/chat-interface branch August 27, 2025 06:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant