@@ -43,11 +43,14 @@ import EmptyState from "./EmptyState";
4343
4444
4545
46+ const BATCH_SIZE = 30 ; // Number of messages to show/load at a time
47+
4648const AgentChatPanel : Component = ( ) => {
4749 let messagesEndRef : HTMLDivElement | undefined ;
4850 let inputRef : HTMLTextAreaElement | undefined ;
4951 // model browser state is held in signals below
5052 const [ inputValue , setInputValue ] = createSignal ( "" ) ;
53+ const [ visibleCount , setVisibleCount ] = createSignal ( BATCH_SIZE ) ; // how many messages to show from the end
5154 const [ contextFiles , setContextFiles ] = createSignal < string [ ] > ( [ ] ) ;
5255 const [ initialized , setInitialized ] = createSignal ( false ) ;
5356 const [ hasApiKey , setHasApiKey ] = createSignal < boolean | null > ( null ) ;
@@ -268,6 +271,25 @@ const AgentChatPanel: Component = () => {
268271 updateSettings ( { aiModel : model } ) ;
269272 }
270273
274+ // Only render last N messages to keep DOM lean (user can load more)
275+ const visibleMessages = createMemo ( ( ) => {
276+ const all = agentMessages ;
277+ const count = visibleCount ( ) ;
278+ return all . slice ( - count ) ;
279+ } ) ;
280+
281+ // Number of older messages not currently visible
282+ const hiddenCount = createMemo ( ( ) => {
283+ const total = agentMessages . length ;
284+ const visible = visibleCount ( ) ;
285+ return Math . max ( 0 , total - visible ) ;
286+ } ) ;
287+
288+ // Load older messages in batches
289+ function loadMoreMessages ( ) {
290+ setVisibleCount ( prev => prev + BATCH_SIZE ) ;
291+ }
292+
271293 // Auto-scroll on new messages
272294 createEffect ( ( ) => {
273295 const _len = agentMessages . length ;
@@ -608,7 +630,16 @@ const AgentChatPanel: Component = () => {
608630 />
609631 }
610632 >
611- < For each = { agentMessages } >
633+ < Show when = { hiddenCount ( ) > 0 } >
634+ < button
635+ onClick = { loadMoreMessages }
636+ class = "w-full text-center py-2 text-xs hover:bg-opacity-50 transition-colors cursor-pointer"
637+ style = { { color : "var(--text-muted)" , background : "var(--bg-tertiary)" } }
638+ >
639+ Load { Math . min ( BATCH_SIZE , hiddenCount ( ) ) } older messages ({ hiddenCount ( ) } hidden)
640+ </ button >
641+ </ Show >
642+ < For each = { visibleMessages ( ) } >
612643 { ( msg ) => < ChatMessage message = { msg } pendingCommand = { pendingCommand } onApprove = { async ( sid , approved ) => { setPendingCommand ( null ) ; await agentApproveCommand ( sid , approved ) ; } } /> }
613644 </ For >
614645 < Show when = { agentStreaming ( ) && agentStatus ( ) } >
0 commit comments