Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix: avoid viewport dead zone - route re-sync through xterm, not the DOM

Gulumaa42be8c2076
diff --git a/src/renderer/src/components/PtyTerminalView.tsx b/src/renderer/src/components/PtyTerminalView.tsx
index d9faacba..8d0ae583 100644
--- a/src/renderer/src/components/PtyTerminalView.tsx
+++ b/src/renderer/src/components/PtyTerminalView.tsx
@@ -157,16 +157,22 @@ export function PtyTerminalView({ ptyId, onStreamData, onUserPrompt, onToggleFul
} catch { /* host may not be sized yet */ }
if (scrollToEnd) {
try {
- entry.term.scrollToBottom();
// Re-parenting the pooled terminal resets the DOM viewport's
// scrollTop to 0 while xterm's internal scroll state stays at the
- // bottom — so the screen still LOOKS right and scrollToBottom() is a
- // no-op (no state change → no viewport re-sync). The user's first
- // wheel then reads the stale scrollTop≈0 and yanks the view to the
- // very top of history. Force the DOM viewport back in sync; the
- // resulting scroll event also re-syncs xterm's handler state.
- const vp = entry.host.querySelector('.xterm-viewport') as HTMLElement | null;
- if (vp) vp.scrollTop = vp.scrollHeight;
+ // bottom — the screen still LOOKS right, but the user's first wheel
+ // reads the stale scrollTop≈0 and yanks the view to the top of
+ // history. A bare scrollToBottom() can't repair this (the buffer is
+ // already at the bottom internally → no state change → no viewport
+ // re-sync). Writing the DOM scrollTop from out here is no good
+ // either: it races with xterm's ignore-next-scroll-event flag
+ // (scroll events coalesce), which can leave the scrollbar pinned at
+ // max while the buffer sits ABOVE the bottom — then wheeling down is
+ // dead (scrollTop can't exceed max → no event → no re-sync).
+ // Instead force a REAL position change through xterm's own state
+ // machine: one line up, then back to the bottom. Its Viewport then
+ // re-syncs the DOM scrollTop itself, atomically with its flag.
+ entry.term.scrollLines(-1);
+ entry.term.scrollToBottom();
} catch { /* noop */ }
}
};