Skip to content

Fix hunkless file selection in all-files diff - #15325

Merged
samhh merged 2 commits into
masterfrom
samhh/fix-hunkless-file-initial-scroll
Aug 13, 2026
Merged

Fix hunkless file selection in all-files diff#15325
samhh merged 2 commits into
masterfrom
samhh/fix-hunkless-file-initial-scroll

Conversation

@samhh

@samhh samhh commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Prefer the active file as the initial CodeView target when it has no hunks.
  • Skip an imperative scroll when the deferred Details view still points to a CodeView that does not contain the selected file.

Why

Selecting a binary or otherwise hunkless uncommitted file could resolve a hunk from the previously active file. During the deferred Details transition, WorkspacePage could also call scrollTo on the outgoing CodeView, producing an unknown-item warning and leaving the new file off-screen.

User impact

Hunkless files now open at the correct position in the all-files diff, and the stale CodeView warning is avoided without allowing file selection to bounce back.

Validation

  • pnpm -F @gitbutler/lite check
  • Reproduced before and verified after a full Cmd+R reload with a long text file followed by a binary file
  • Confirmed the binary file remained selected and visible, the warning was absent, and same-view file selection still scrolled correctly

samhh added 2 commits August 13, 2026 18:40
Repro: select a commit, wait for its details, then select a non-first hunkless uncommitted file; the diff stays on the first file.
Copilot AI lite review requested due to automatic review settings August 13, 2026 17:46
@samhh
samhh enabled auto-merge August 13, 2026 17:46
@samhh
samhh merged commit 97bd994 into master Aug 13, 2026
39 checks passed
@samhh
samhh deleted the samhh/fix-hunkless-file-initial-scroll branch August 13, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect file targeting/scroll behavior in the Lite workspace “all-files” diff view when selecting uncommitted files that have no hunks (e.g., binary files), preventing the selection from snapping back to a previously active file and avoiding stale-view scroll warnings during deferred Details transitions.

Changes:

  • Ensure initial diff scroll targets the active file’s item ID when the active file is hunkless (instead of using a resolved hunk from another file).
  • Avoid calling scrollTo on a CodeView instance that does not contain the selected file during deferred Details transitions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/lite/ui/src/routes/project/$id/workspace/WorkspacePage.tsx Adds a guard to skip scrolling when the current viewer instance doesn’t contain the selected file item.
apps/lite/ui/src/routes/project/$id/workspace/Details.tsx Threads activeFileItemId through and uses it to pick the initial scroll target when the active file has no hunks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 395 to +399
didScrollToViaFileRef.current = true;
viewerRef.current?.scrollTo({
const viewer = viewerRef.current?.getInstance();
// Details selection is deferred, so the ref may still point at a viewer without this file.
if (!viewer?.getItem(itemId)) return;

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.

2 participants