Skip to content

fix(ui): use full agent-note set for section geometry measurement#243

Open
aldevv wants to merge 1 commit intomodem-dev:mainfrom
aldevv:fix/bottom-edge-with-notes
Open

fix(ui): use full agent-note set for section geometry measurement#243
aldevv wants to merge 1 commit intomodem-dev:mainfrom
aldevv:fix/bottom-edge-with-notes

Conversation

@aldevv
Copy link
Copy Markdown

@aldevv aldevv commented May 8, 2026

User-visible: with agent notes attached, scrolling to the last line of the diff bounces the viewport upward by ~1–2 lines (~the height of the off-top note rows).

Steps to reproduce (on main)

  1. hunk diff <range> on a multi-file diff.
  2. Attach agent comments on at least one file other than the last one (so notes scroll off the top while you reach the bottom):
    echo '{"comments":[{"filePath":"<early-file>","hunkNumber":1,"summary":"x","rationale":"y"}]}' \
      | hunk session comment apply --repo <repo> --stdin
  3. Scroll all the way down to the last line of the last file.
  4. Try to scroll one line further. The viewport snaps up by ~1–2 lines instead of staying put.

Without notes attached, the bottom edge is stable.

Fix: section geometry now measures with the full agent-note set so total content height is stable regardless of scroll position. Rendering still uses the viewport-restricted set, so painting cost is unchanged.

No user-facing docs or workflows change.

Fixes #234.

The visible-viewport agent-note set is correct for rendering (skip painting
cards on off-screen files) but using it for section measurement made total
content height fluctuate with scroll position: as a file with notes left
the viewport its geometry shrank back to the no-notes baseline, which
shrank totalContentHeight, which tightened clampReviewScrollTop's ceiling
and snapped the viewport upward by the height of the off-top note rows.

Always include notes in geometry for stable bottom-edge clamping; rendering
keeps using visibleAgentNotesByFile.

Fixes modem-dev#234.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 8, 2026

Greptile Summary

Fixes a viewport snap-back bug where sectionGeometry was measured with visibleAgentNotesByFile, causing totalContentHeight to shrink whenever a note-bearing file left the visible viewport and making clampReviewScrollTop yank the user back up. The fix is a one-variable swap in a single useMemo — measurement now uses allAgentNotesByFile; the rendering path at line 1101 is untouched and still uses visibleAgentNotesByFile for painting efficiency.

  • sectionGeometry memo now depends on allAgentNotesByFile instead of visibleAgentNotesByFile, and the dependency array is updated to match.
  • baseSectionGeometry (no-notes baseline) and visibleAgentNotesByFile (render-only) are both left intact and used for their original purposes.

Confidence Score: 5/5

Safe to merge — a minimal, well-commented swap in a single memo with no side-effects on the rendering path.

The change is a one-variable substitution in a single useMemo. The new dependency (allAgentNotesByFile) is already computed and stable, the old one (visibleAgentNotesByFile) still drives rendering, and the dependency array is correctly updated. The PR description precisely diagnoses the root cause, the comment in the source mirrors the explanation, and the test suite is green.

No files require special attention.

Important Files Changed

Filename Overview
src/ui/components/panes/DiffPane.tsx Swaps visibleAgentNotesByFileallAgentNotesByFile in the sectionGeometry memo so content-height is stable across scroll positions; rendering path is unchanged.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[allAgentNotesByFile\nfull set, all files] -->|BEFORE: only used for visibleAgentNotesByFile| B
    A -->|AFTER: also used here| C

    B[visibleAgentNotesByFile\nviewport + selected only] -->|rendering| D[DiffSection paint]

    C[sectionGeometry\nmemo] -->|stable heights| E[estimatedBodyHeights]
    E --> F[fileSectionLayouts]
    F --> G[totalContentHeight]
    G --> H[clampReviewScrollTop\nstable ceiling]
Loading

Reviews (1): Last reviewed commit: "fix(ui): use full agent-note set for sec..." | Re-trigger Greptile

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.

Bottom-edge scroll snap-back when agent notes are attached

1 participant