Skip to content

Commit 38208a9

Browse files
committed
🤖 fix: use double RAF in jumpToBottom for reliable scroll position
When switching workspaces, jumpToBottom was executing synchronously before browser layout was complete. This caused scrolling to land 'almost at the bottom' instead of fully at the bottom. The fix uses double requestAnimationFrame (matching performAutoScroll): - First frame: allows DOM updates to complete - Second frame: measures accurate scrollHeight after layout setAutoScroll(true) is set immediately to prevent flicker of the 'jump to bottom' button.
1 parent 055145c commit 38208a9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/browser/hooks/useAutoScroll.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ export function useAutoScroll() {
3838
}, []); // No deps - ref ensures we always check current value
3939

4040
const jumpToBottom = useCallback(() => {
41-
if (contentRef.current) {
42-
contentRef.current.scrollTop = contentRef.current.scrollHeight;
43-
setAutoScroll(true);
44-
}
41+
if (!contentRef.current) return;
42+
43+
// Double RAF: First frame for DOM updates (async highlighting, image loads),
44+
// second frame to scroll after layout is complete
45+
requestAnimationFrame(() => {
46+
requestAnimationFrame(() => {
47+
if (contentRef.current) {
48+
contentRef.current.scrollTop = contentRef.current.scrollHeight;
49+
}
50+
});
51+
});
52+
setAutoScroll(true);
4553
}, []);
4654

4755
const handleScroll = useCallback((e: React.UIEvent<HTMLDivElement>) => {

0 commit comments

Comments
 (0)