Skip to content

fix(desktop): ensure terminal scrolls to bottom after restore and resize - #864

Merged
Kitenite merged 1 commit into
mainfrom
potential-race-condition-go-to-bottom
Jan 21, 2026
Merged

Kitenite merged 1 commit into
mainfrom
potential-race-condition-go-to-bottom

Conversation

@Kitenite

@Kitenite Kitenite commented Jan 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Uses xterm.write() callback with requestAnimationFrame to scroll to bottom only after content is fully rendered
  • Fixes race condition where terminal viewport could remain scrolled up after cold restore, hot restore, or visibility/resize changes
  • Preserves scroll position if user had manually scrolled up before resize

Test plan

  • Open a terminal with existing scrollback history, close and reopen app - terminal should scroll to bottom
  • Switch tabs away from terminal and back - should maintain scroll position (or scroll to bottom if was at bottom)
  • Resize terminal while it has scrollback - should scroll to bottom if was at bottom, otherwise preserve position
  • Tab between terminals with different scroll positions - each should maintain its own scroll state

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal scroll-to-bottom behavior during content restoration and session recovery
    • Fixed terminal scrolling position after resize events
    • Enhanced scroll handling to maintain bottom-of-view positioning during initialization
    • Optimized scroll behavior when toggling terminal visibility

✏️ Tip: You can customize this high-level summary in your review settings.

Use xterm.write() callback and requestAnimationFrame to scroll to bottom
only after content is fully rendered. This fixes a race condition where
the terminal viewport could remain scrolled up after cold restore, hot
restore, or visibility/resize changes.
@coderabbitai

coderabbitai Bot commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds scheduled scroll-to-bottom behavior to the terminal component across multiple restoration and rendering paths. It introduces helpers using requestAnimationFrame to scroll to the bottom after writing scrollback, resizing, visibility changes, and restoration, ensuring the view updates correctly after layout changes.

Changes

Cohort / File(s) Summary
Main Terminal Component
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
Introduces scheduleScrollToBottom helper that scrolls to bottom on next animation frame with mount/instance checks. Applies callback after xterm.write operations during restoration and scrollback. Detects user position on visibility changes and schedules scroll if at bottom.
Terminal Restoration Helpers & Hooks
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts, useTerminalColdRestore.ts, useTerminalRestore.ts
Adds scroll-to-bottom restoration on resize by detecting previous scroll position. Modifies cold restore to include post-write scroll callback. Introduces scheduleFitAndScroll helper in general restore path with guards for stale references, replacing direct animation frame blocks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #838: Modifies the same Terminal restore helpers and hooks (useTerminalColdRestore, useTerminalRestore, helpers.ts, Terminal.tsx) with overlapping restoration sequencing logic.
  • #728: Modifies terminal scroll-restoration logic including Terminal.tsx and related helpers for viewport/scrollback handling.
  • #150: Touches the same terminal scrollback handling code path in Terminal.tsx during restoration.

Suggested reviewers

  • AviPeltz

Poem

🐰 Hop, scroll, and fit with care,
Animation frames float through the air,
No jumping views or stale refs in sight,
The terminal glides with scheduling might! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing terminal scroll-to-bottom behavior after restore and resize operations, which matches the core objective of the changeset.
Description check ✅ Passed The description includes a summary of changes, testing plan with specific scenarios, and additional context. However, it omits required template sections: Related Issues, Type of Change, and Additional Notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Kitenite
Kitenite merged commit 7e85c0f into main Jan 21, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant