Skip to content

[Bug] Terminal scroll-to-top persists — happens after input, not just tab switching #573

Closed

Description

@waleedkadous

Problem

After the fix in #560 (externally tracked scroll state) and #563 (safeFit condition fix), terminals still scroll to the top unexpectedly. The issue is NOT limited to tab switching — it can happen after every input in some terminals.

Previous Fixes

Hypotheses

1. baseY check race condition (most likely)

In safeFit() (Terminal.tsx:388-392):

const baseY = term.buffer?.active?.baseY;
if (!baseY) {
  fitAddon.fit();
  return;
}

If baseY reads as 0 or undefined during a buffer reflow or mid-write, safeFit calls fitAddon.fit() WITHOUT scroll preservation. This is the unprotected path.

2. onScroll handler reads during reflow

The term.onScroll() handler (line 368-374) reads term.buffer.active.viewportY from the buffer. During fitAddon.fit() reflow, these values may be stale or intermediate, corrupting scrollState.

3. ResizeObserver triggering during writes

If terminal output causes subtle layout changes that trigger ResizeObserver → debouncedFit → safeFit, this could cause repeated scroll resets after every keystroke.

Reproduction

  • Use a terminal with significant scrollback history
  • Type commands — terminal may scroll to top after output arrives
  • More likely in terminals with active output

Suggested Investigation

  1. Add console.log tracing in safeFit() — log baseY, scrollState, and whether the unprotected path is taken
  2. Log when debouncedFit is triggered and by what (ResizeObserver vs visibilitychange)
  3. Check if term.onScroll fires during fitAddon.fit() and what values it reports
  4. Consider using scrollState.baseY as fallback when term.buffer.active.baseY returns 0/undefined

Activity

  1. added
    bug
    on Feb 26, 2026
  2. added 2 commits that reference this issue on Feb 26, 2026
  3. waleedkadous commented on Mar 4, 2026

    @waleedkadous
    ContributorAuthor

    Significantly improved after the scroll-to-top fix. Closing as resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions