fix(agent): use containerRef from useScrollPosition to memorize scroll position#13744
Merged
kangfenmao merged 3 commits intomainfrom Mar 24, 2026
Merged
fix(agent): use containerRef from useScrollPosition to memorize scroll position#13744kangfenmao merged 3 commits intomainfrom
kangfenmao merged 3 commits intomainfrom
Conversation
- Pass messages and session data to AgentSessionMessages via props - Compute and pass sessionTopicId in AgentChat; stop internal topic fetch - Update related typings and imports
This reverts commit 39d192d.
DeJeune
approved these changes
Mar 24, 2026
kangfenmao
approved these changes
Mar 24, 2026
kangfenmao
approved these changes
Mar 24, 2026
MyPrototypeWhat
pushed a commit
that referenced
this pull request
Mar 30, 2026
…l position (#13744) ### What this PR does Before this PR: Agent chat page created a separate `useRef` for `scrollContainerRef` instead of using the one provided by `useScrollPosition`, causing the hook to never observe the actual scroll container. As a result, scroll positions were not memorized when switching between agent sessions. After this PR: Uses `containerRef` returned from `useScrollPosition` as the scroll container ref, so the hook correctly tracks and restores scroll positions for agent sessions. ### Why we need it and why it was done in this way The `useScrollPosition` hook needs its own `containerRef` to be attached to the scrollable DOM element in order to read/write `scrollTop`. The previous code ignored this ref and created a standalone one, breaking the memorization mechanism. The following tradeoffs were made: N/A The following alternatives were considered: N/A ### Breaking changes None ### Special notes for your reviewer Minimal one-line fix — just replaced the standalone `useRef` with the `containerRef` from the hook. ### Checklist - [x] PR: The PR description is expressive enough and will help future contributors - [x] Code: [Write code that humans can understand](https://en.wikiquote.org/wiki/Martin_Fowler#code-for-humans) and [Keep it simple](https://en.wikipedia.org/wiki/KISS_principle) - [x] Refactor: You have [left the code cleaner than you found it (Boy Scout Rule)](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html) - [ ] Upgrade: Impact of this change on upgrade flows was considered and addressed if required - [ ] Documentation: A [user-guide update](https://docs.cherry-ai.com) was considered and is present (link) or not required. Check this only when the PR introduces or changes a user-facing feature or behavior. - [x] Self-review: I have reviewed my own code (e.g., via [`/gh-pr-review`](/.claude/skills/gh-pr-review/SKILL.md), `gh pr diff`, or GitHub UI) before requesting review from others ### Release note ```release-note fix: Fixed agent chat page not memorizing scroll position when switching between sessions ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Before this PR:
Agent chat page created a separate
useRefforscrollContainerRefinstead of using the one provided byuseScrollPosition, causing the hook to never observe the actual scroll container. As a result, scroll positions were not memorized when switching between agent sessions.After this PR:
Uses
containerRefreturned fromuseScrollPositionas the scroll container ref, so the hook correctly tracks and restores scroll positions for agent sessions.Why we need it and why it was done in this way
The
useScrollPositionhook needs its owncontainerRefto be attached to the scrollable DOM element in order to read/writescrollTop. The previous code ignored this ref and created a standalone one, breaking the memorization mechanism.The following tradeoffs were made: N/A
The following alternatives were considered: N/A
Breaking changes
None
Special notes for your reviewer
Minimal one-line fix — just replaced the standalone
useRefwith thecontainerReffrom the hook.Checklist
/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note