Skip to content

Adding annotation in FileDiff + Virtualizer causes scroll jump #1075

Description

@jonatanklosko

Inserting an annotation with many hunks above causes a scroll jump. This affects FileDiff, not CodeView.

Reproduction

Source: diffs-jump.tar.gz

The README.md includes agent notes on the alleged cause and possible solutions. I also paste it below:

Notes

Mechanism

  • Changing the lineAnnotations array identity makes
    VirtualizedFileDiff.syncLineAnnotations call resetLayoutCache(),
    which wipes all measured heightDeltas for the file (here: 60
    annotation rows ≈ 28px each), even though annotations never renumber
    lines.
  • The file re-renders at estimated line heights synchronously in the
    React commit (and forces a reflow mid-commit), so content above the
    viewport transiently shrinks by the forgotten corrections.
  • Chromium's native scroll anchoring (overflow-anchor: auto, the
    default on the scroll container) "corrects" scrollTop against that
    transient layout. The virtualizer then re-measures only the rows near
    the new position, so nothing ever moves the scroll back.

Two independent changes each make the jump disappear, pointing at the
two halves of the bug:

  • overflow-anchor: none on the scroll container — this is exactly
    what CodeView (advanced mode) does in setup(), plus its own
    anchor-capture/correction per render pass, which is why CodeView
    apps don't hit this. Simple mode never got that treatment.
  • Preserving heightDeltas across annotation-only resets (they stay
    valid — annotation changes don't shift line indexes). Document edits
    (applyDocumentChange, the other reset site) need the keys remapped
    by the edit's line delta instead — the transform the editor already
    applies to annotations — plus the capturePendingLayoutAnchor
    bracket that advanced mode has and simple mode lacks, to absorb the
    residual error around the caret.

Demo

diffs-jump.mp4

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions