[PR #15265] app/ui: fix unnecessary re-renders when toggling sidebar #15097

Open
opened 2026-04-13 01:10:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15265
Author: @matteocelani
Created: 4/3/2026
Status: 🔄 Open

Base: mainHead: fix/sidebar-rerender-performance


📝 Commits (1)

  • 15759bc app/ui: fix unnecessary re-renders when toggling sidebar

📊 Changes

3 files changed (+16 additions, -12 deletions)

View changed files

📝 app/ui/app/src/components/Chat.tsx (+11 -10)
📝 app/ui/app/src/components/Message.tsx (+2 -1)
📝 app/ui/app/src/components/MessageList.tsx (+3 -1)

📄 Description

Toggling the sidebar causes all Message components to re-render, including expensive syntax highlighting via Shiki. This makes the UI feel sluggish (~1-2s delay), especially in conversations with code blocks.

The root cause is an inline arrow function for onEditMessage in Chat.tsx that creates a new reference on every render, breaking React.memo on Message. Additionally, the Message memo comparator is missing lastToolQuery, and MessageList itself is not memoized.

Changes:

  • Chat.tsx: wrap handleEditMessage in useCallback and pass it directly instead of an inline arrow
  • Message.tsx: add missing lastToolQuery to the React.memo comparator
  • MessageList.tsx: wrap component in React.memo to skip re-renders when props are unchanged

To reproduce: open a chat with a long code response, then toggle the sidebar repeatedly.

Fixes #12959


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15265 **Author:** [@matteocelani](https://github.com/matteocelani) **Created:** 4/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/sidebar-rerender-performance` --- ### 📝 Commits (1) - [`15759bc`](https://github.com/ollama/ollama/commit/15759bcc36ac784986d806269cb5e7b07e227a49) app/ui: fix unnecessary re-renders when toggling sidebar ### 📊 Changes **3 files changed** (+16 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `app/ui/app/src/components/Chat.tsx` (+11 -10) 📝 `app/ui/app/src/components/Message.tsx` (+2 -1) 📝 `app/ui/app/src/components/MessageList.tsx` (+3 -1) </details> ### 📄 Description Toggling the sidebar causes all Message components to re-render, including expensive syntax highlighting via Shiki. This makes the UI feel sluggish (~1-2s delay), especially in conversations with code blocks. The root cause is an inline arrow function for `onEditMessage` in Chat.tsx that creates a new reference on every render, breaking `React.memo` on Message. Additionally, the Message memo comparator is missing `lastToolQuery`, and MessageList itself is not memoized. Changes: - `Chat.tsx`: wrap `handleEditMessage` in `useCallback` and pass it directly instead of an inline arrow - `Message.tsx`: add missing `lastToolQuery` to the `React.memo` comparator - `MessageList.tsx`: wrap component in `React.memo` to skip re-renders when props are unchanged To reproduce: open a chat with a long code response, then toggle the sidebar repeatedly. Fixes #12959 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 01:10:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#15097