Skip to content

Commit a1ba71d

Browse files
authored
🤖 fix: use double RAF in jumpToBottom for reliable scroll position (#887)
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. --- _Generated with `mux`_
1 parent 055145c commit a1ba71d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
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>) => {

‎src/cli/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ if (subcommand === "run") {
4242
process.argv.splice(2, 1);
4343
// eslint-disable-next-line @typescript-eslint/no-require-imports
4444
require("./api");
45-
} else if (subcommand === "desktop" || (isElectron && (subcommand === undefined || isElectronLaunchArg))) {
45+
} else if (
46+
subcommand === "desktop" ||
47+
(isElectron && (subcommand === undefined || isElectronLaunchArg))
48+
) {
4649
// Explicit `mux desktop`, or Electron runtime with no subcommand / Electron launch args
4750
launchDesktop();
4851
} else {

0 commit comments

Comments
 (0)