nanocoder
nanocoder copied to clipboard
refactor: separate ChatHistory and ChatInput into distinct components
Summary
The ChatInterface component currently combines two concerns with different lifecycles:
- ChatHistory (ink's Static component) - should never unmount, holds frozen terminal output
- ChatInput (user input, tool confirmations, etc.) - can mount/unmount based on mode
Background
PR #217 fixed a memory leak where entering modal modes (config wizard, model selector, etc.) would unmount the entire ChatInterface, causing ink's Static component to be destroyed and recreated. This triggered massive memory growth (4GB in ~14 seconds).
The fix added a hideInput prop to hide the input area during modal modes, but this is a workaround. Proper separation would prevent this class of bug entirely.
Proposed Architecture
// In App.tsx
<ChatHistory
staticComponents={staticComponents}
queuedComponents={chatComponents}
/> {/* Always mounted - never unmounts */}
{!isModal && (
<ChatInput
onSubmit={...}
pendingToolCalls={...}
/>
)} {/* Can mount/unmount freely */}
{isModal && <ModalSelectors ... />}
Benefits
- ChatHistory can't accidentally unmount (prevents this class of bug)
- Single responsibility for each component
- Cleaner props (history doesn't need input handlers, input doesn't need static components)
- Easier to test independently
Files to Modify
source/app/components/ChatInterface.tsx→ split intoChatHistory.tsxandChatInput.tsxsource/app/App.tsx- render components separately- Update tests accordingly