@@ -177,6 +177,10 @@ func (m *UI) Init() tea.Cmd {
177 return tea.Batch(cmds...)
177 return tea.Batch(cmds...)
180+// sessionLoadedDoneMsg indicates that session loading and message appending is
182+type sessionLoadedDoneMsg struct{}
180// Update handles updates to the UI model.
184// Update handles updates to the UI model.
181func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
185func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182 var cmds []tea.Cmd
186 var cmds []tea.Cmd
@@ -194,7 +198,15 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
194 for _, message := range msgs {
198 for _, message := range msgs {
195 m.chat.AppendMessage(message)
199 m.chat.AppendMessage(message)
201+ // Notify that session loading is done to scroll to bottom. This is
202+ // needed because we need to draw the chat list first before we can
203+ // scroll to bottom.
204+ cmds = append(cmds, func() tea.Msg {
205+ return sessionLoadedDoneMsg{}
207+ case sessionLoadedDoneMsg:
197 m.chat.ScrollToBottom()
208 m.chat.ScrollToBottom()
198 case sessionFilesLoadedMsg:
210 case sessionFilesLoadedMsg:
199 m.sessionFiles = msg.files
211 m.sessionFiles = msg.files
200 case pubsub.Event[history.File]:
212 case pubsub.Event[history.File]: