ollama - ✅(Solved) Fix app/ui: chat doesn't scroll to the bottom on page refresh or when switching conversations [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15997Fetched 2026-05-07 03:31:57
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1

Root Cause

  1. On page refresh, the tracking ref is initialized with the current chat ID, so the "did the chat change?" check immediately fails — it thinks you're already on this chat.
  2. The ref gets updated unconditionally on every render, even before messages have actually loaded. So when messages finally arrive and the effect re-runs, it thinks nothing changed because the ref was already set.

Fix Action

Fixed

PR fix notes

PR #16001: app/ui: fix scroll-to-bottom not triggering on page refresh or chat switch

Description (problem / solution / changelog)

The useLayoutEffect that scrolls to the bottom on chat switch has two bugs:

  1. prevChatIdRef is initialized with the current chatId, so on page refresh the 'did chatId change?' check immediately fails and the scroll never fires.

  2. The ref is updated unconditionally on every effect run, even when messages haven't loaded yet (length === 0). When messages arrive and the effect re-runs, the check fails because the ref was already set.

Fix: initialize prevChatIdRef as null and move the ref update inside the scroll branch so it only fires after a successful scroll-to-bottom.

Fixes #15997

Changed files

  • app/ui/app/src/components/Chat.tsx (modified, +2/-2)
RAW_BUFFERClick to expand / collapse

What is the issue?

When you open a long chat via a direct link or refresh the page, the chat stays scrolled to the top instead of jumping to the most recent messages at the bottom. The same can happen intermittently when switching between chats — sometimes the scroll-to-bottom just doesn't fire.

Why it happens The scroll-to-bottom logic tracks the previous chat ID to detect navigation. Two problems:

  1. On page refresh, the tracking ref is initialized with the current chat ID, so the "did the chat change?" check immediately fails — it thinks you're already on this chat.
  2. The ref gets updated unconditionally on every render, even before messages have actually loaded. So when messages finally arrive and the effect re-runs, it thinks nothing changed because the ref was already set.

Expected behavior Opening any existing chat — whether via navigation or page refresh — should always scroll to the most recent messages at the bottom.

Relevant log output

OS

macOS

GPU

Intel, Apple

CPU

Apple

Ollama version

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING