Commit 62fb900
Fix scroll behavior when switching between chats (dyad-sh#2643)
## Summary
- Fix scroll behavior when switching between chats with existing
messages
- Use double `requestAnimationFrame` to wait for Virtuoso to render
before scrolling to bottom when switching chats
- Distinguish between chat switches and new message sends to handle
scrolling appropriately
- Avoid premature scrolling when switching to chats where messages
haven't been fetched yet
## Test plan
1. Open Dyad and start a chat with some messages
2. Start another chat with messages
3. Switch between chats and verify scroll position stays at the bottom
4. Send a new message and verify it scrolls to show the new message
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2643"
target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
</picture>
</a>
<!-- devin-review-badge-end -->
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes chat auto-scroll to keep the view anchored at the bottom when
switching chats or sending messages. Prevents flicker and jumps before
messages render.
- **Bug Fixes**
- Distinguish chat switches vs new sends; adjust scroll timing
accordingly.
- On chat switch with existing messages, wait for Virtuoso to render
(double requestAnimationFrame), then scroll to bottom instantly.
- On new message send, wait for the placeholder to render (double
requestAnimationFrame) before scrolling; skip auto-scroll when switching
to a chat with no messages yet.
<sup>Written for commit 8814a60.
Summary will update on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Scoped to `ChatPanel` scroll timing logic; risk is limited to possible
UI regressions (missed/extra scroll) when switching chats or starting
streams.
>
> **Overview**
> Fixes `ChatPanel` auto-scroll behavior by **distinguishing chat
switches from new stream starts** and delaying the scroll until after
Virtuoso has rendered.
>
> On chat switch, it now scrolls to bottom *only after messages exist*
(avoiding premature scroll before fetch/render) and uses a double
`requestAnimationFrame` with `instant` scrolling; on new message sends
(`streamCount` changes), it similarly waits for render before scrolling
with the default behavior.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
8814a60. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 06997f9 commit 62fb900
1 file changed
Lines changed: 29 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
82 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
83 | 91 | | |
84 | 92 | | |
85 | | - | |
86 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
87 | 114 | | |
88 | 115 | | |
89 | 116 | | |
| |||
102 | 129 | | |
103 | 130 | | |
104 | 131 | | |
105 | | - | |
106 | 132 | | |
107 | 133 | | |
108 | 134 | | |
| |||
0 commit comments