Skip to content

Markdown viewer loses scroll position when switching tabs or returning after opening a hyperlink #5181

Closed

Description

@erikmackinnon

Summary

The built-in Markdown viewer in the right-hand pane loses its reading position when switching to another tab and returning. Clicking a hyperlink that opens a new browser tab and then returning to the still-open Markdown tab causes the same reset to the top. The tab should retain its position for as long as it remains open.

Versions and environment

  • Reproduced against a clean public main checkout at fdcc4e3eafb032bfed76b9fd4708abbb75802481 on 2026-10-07.
  • Source investigation: Fedora Linux 44 (Workstation Edition), Node.js v24.15.0, Google Chrome 154.0.8037.92, headless viewport 1400 × 900.
  • The original report concerns the bb right-hand Markdown pane; the reporter's desktop version was not independently established.
  • Verification used the real ThreadSecondaryPanel, built-in file preview, Markdown renderer, and application styles in an isolated loopback Vite harness, with deterministic file content. It did not launch or modify the installed desktop runtime.
  • No agent provider is required. The reporter disabled Markdown PRO and still reproduced the problem; the source/browser reproduction also loaded no plugin.

Steps to reproduce

  1. In a bb project checkout, create a long Markdown fixture:

    python3 - <<'PY'
    from pathlib import Path
    text = "\n\n".join(
        f"## Section {i}\n\nParagraph {i}." for i in range(1, 81)
    )
    text += "\n\n[Open a new tab](https://example.com/)\n"
    Path("scroll-repro.md").write_text(text)
    PY
  2. Open scroll-repro.md in the thread's right-hand pane. From a terminal in that bb thread, bb thread open scroll-repro.md opens the file.

  3. Open another browser tab in the pane, then select the Markdown tab again.

  4. Scroll the Markdown document partway down, for example to Section 30.

  5. Select the other browser tab, then return to scroll-repro.md.

  6. Observe that the document is back at Section 1.

Hyperlink variant:

  1. With the Markdown document active, scroll down to its Open a new tab hyperlink.
  2. Click the hyperlink, allowing bb to open/select the new browser tab.
  3. Return to scroll-repro.md; observe that it is back at Section 1.

The smallest source-level reproduction needs only a ready long Markdown document, its real secondary-panel tab, and a browser tab. Cached, already-ready document data is sufficient; a file reload is not necessary.

Expected vs actual

Expected: returning to a still-open Markdown tab restores the same reading position, including after opening a hyperlink in a new tab.

Actual: the document returns to the top. The pristine-source headless browser assertions produced:

FAIL ordinary tab switching Expected values to be strictly equal:

0 !== 960

FAIL hyperlink opens a new tab Expected values to be strictly equal:

0 !== 4841

FAIL switch to a short Markdown document and back Expected values to be strictly equal:

0 !== 960

FAIL restore after loading Expected values to be strictly equal:

0 !== 960

PASS closed and reopened document starts at top
{"passed":1,"failed":4}

These are measured scrollTop values in pixels, not an inferred visual reset. Closing and reopening a document was included as a control and correctly started at zero.

Evidence

Investigation report: source trace and browser/test results are recorded in this section. Originating bb investigation: @thread:thr_23dguf3j4u.

Observed lifecycle:

Diagnosis: the tab lifecycle discards DOM scroll state without retaining it for the still-open document. No explicit reset policy or documented requirement to restart reading at the top was found.

Local fix verified, not published: record native scroll events in a per-open-tab cache owned by the secondary panel, restore when the ready Markdown body mounts, and prune closed-tab entries. Restore after the document finishes loading, rather than against its loading placeholder. Do not overwrite the saved offset during outgoing cleanup after layout clamping.

Regression coverage uses the real panel, WorkspaceFilePreviewTabContent, and Markdown renderer with mocked file retrieval. Both reported scenarios failed before the fix on repeated runs. Six regression cases pass with the fix: ordinary tab switching, hyperlink return, independent Markdown positions, restoration after loading, outgoing layout clamping, and close/reopen cleanup. The related suites pass 68 tests in total; app typecheck and lint also pass (existing lint warnings remain).

The same browser loop, first against pristine production files from HEAD and then against the local patch, passed all five scenarios after the fix. No installed runtime changes or PR were made.

What you ruled out

Suggested priority and effort

Required triage metadata: area label ui, built-in issue type Bug. GitHub denied the reporter permission to set both fields (AddLabelsToLabelable and UpdateIssueIssueType); a maintainer needs to apply them. Per the filing guide, priority and effort belong in built-in issue fields, not labels.

Medium priority, likely low effort. Repeated tab navigation interrupts reading long documents; no document data is lost. The current workaround is to manually find the reading position again.

Checks

  • Reproduced on the main source commit identified above; installed desktop end-to-end verification is explicitly outside this investigation.
  • Searched open and closed issues for the same problem.
  • Included the originating bb thread reference and investigation evidence; this body ends with the required attribution.

AGENT GENERATED

Activity

  1. added theissue type on Oct 8, 2026
  2. added
    ui
    confirmed-repro
    on Oct 8, 2026
  3. bb-slop-cop commented on Oct 8, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low; labels ui, confirmed-repro.
    • Report: Reproduction and root cause — REPRODUCED, high confidence, repeated in a second clean trusted checkout.
    • Root cause: switching active surfaces discards the file scroll container without retaining a reading offset for its still-open tab.
    • Fix: ready PR #5185, not merged; 290 changed text lines across 4 files.
    • Verification: four regressions fail before the fix; 67 tests, app typecheck, and lint pass after it. All five native Chrome scenarios pass with the fix. Installed-desktop and Safari verification are not claimed.
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

    confirmed-reproui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions