Performance issue with long streams #32

Open
opened 2026-02-16 02:17:46 -05:00 by yindo · 0 comments
Owner

Originally created by @wylswz on GitHub (Aug 16, 2025).

I was streaming llm output to UI token-by-token, and the webpage gets totally unresponsive after like 5000 words. However, when loading chat history using setMessages(), everything is ok.

Here is my code

export const ChatInterface: React.FC<ChatInterfaceProps> = ({
  sessionId,
}: ChatInterfaceProps) => {
  const handler = useChat({
    transport: new DefaultChatTransport({
      api: '/api/chat',
      body: {
        session_id: sessionId,
      },
    }),
  })
  
  useEffect(() => {
    getChatHistory(sessionId).then(messages => {
      handler.setMessages(messages.map(toMessage))
    })
    
  }, [sessionId])

  return (
    <div
      style={{
        height: 'calc(100vh - 120px)',
      }}
    >
      <ChatSection handler={handler} className="w-full">
        <ChatMessages/>
        <ChatInput>
          <ChatInput.Form>
            <ChatInput.Field placeholder="Type your message..." />
            <ChatInput.Upload />
            <ChatInput.Submit />
          </ChatInput.Form>
        </ChatInput>
      </ChatSection>
    </div>
  )
}
Originally created by @wylswz on GitHub (Aug 16, 2025). I was streaming llm output to UI token-by-token, and the webpage gets totally unresponsive after like 5000 words. However, when loading chat history using setMessages(), everything is ok. Here is my code ```tsx export const ChatInterface: React.FC<ChatInterfaceProps> = ({ sessionId, }: ChatInterfaceProps) => { const handler = useChat({ transport: new DefaultChatTransport({ api: '/api/chat', body: { session_id: sessionId, }, }), }) useEffect(() => { getChatHistory(sessionId).then(messages => { handler.setMessages(messages.map(toMessage)) }) }, [sessionId]) return ( <div style={{ height: 'calc(100vh - 120px)', }} > <ChatSection handler={handler} className="w-full"> <ChatMessages/> <ChatInput> <ChatInput.Form> <ChatInput.Field placeholder="Type your message..." /> <ChatInput.Upload /> <ChatInput.Submit /> </ChatInput.Form> </ChatInput> </ChatSection> </div> ) } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/chat-ui#32