Skip to content

fix: show the empty state when the selected file leaves the working copy - #31

Merged
ashproto merged 1 commit into
nextfrom
fix/clear-vanished-working-selection
Aug 9, 2026
Merged

fix: show the empty state when the selected file leaves the working copy#31
ashproto merged 1 commit into
nextfrom
fix/clear-vanished-working-selection

Conversation

@ashproto

@ashproto ashproto commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Reported by Codex review on the v0.4.0 promotion (#30). next is protected by a ruleset requiring a PR, so the fix lands here and #30 picks it up.

The bug

resolveSection returns null once the selected path is in no list — its last change was committed or discarded, so the file has left the working copy. But diffKey tested only selectedFile:

selectedFile !== null ? `${selectedFile}::${section}::…` : ""

so the key stayed non-empty and the effect fetched an unstaged diff for a file with nothing to diff. The pane then rendered an empty diff instead of the nothing-selected state, while no row could highlight — the row test at :180/:187 already requires a matching section, which is the one place that got it right.

(Small correction to the report: it says the template tests only selectedFile. That is true of the pane branch at :573, but not of the row highlight, which does check section. The net effect described is right.)

The fix

Gate diffKey and the pane branch on section !== null.

I took that option over the other one offered — clearing the selection — for two reasons:

  • No state written from a derived or an effect. Clearing would mean mutating store state in reaction to a derived going null, which needs a guard against re-entry and is the kind of thing that turns into a loop later.
  • It preserves "follow the file wherever it went", which is exactly what the section resolution exists for. If the path comes back — the user edits it again — the selection resumes rather than having been silently dropped.

Verification

npm run check 530 files / 0 errors · npm test 388 passed · cargo test 232 + 7.

Being straight about the limits: there is no WorkingCopyView test harness, and the diff fetch sits behind isTauri(), so neither vitest nor the browser preview can exercise this path. The change is two conditions verified by reading and the type gate. Worth a click in a running build — select a file, discard its last change, and confirm the pane says "Select a file to view its diff." rather than showing an empty diff.

🤖 Generated with Claude Code

`resolveSection` returns null once the path is in no list — its last change was
committed or discarded, so the file is no longer part of the working copy. But
`diffKey` tested only `selectedFile`, so it stayed non-empty and the effect
fetched an unstaged diff for a file with nothing to diff. No row could
highlight, since the row test already requires a matching section, while the
pane rendered an empty diff instead of "Select a file to view its diff."

Gate both on `section !== null` rather than clearing the selection: no state
written from a derived or an effect, and it keeps the "follow the file wherever
it went" behaviour the section resolution exists for — if the path comes back,
the selection resumes instead of having been silently dropped.

Reported by Codex review on the v0.4.0 promotion (#30).

Verified by reading plus `npm run check`; there is no WorkingCopyView test
harness, and the path is behind `isTauri()` so the browser preview cannot reach
it either. npm run check 530 files 0 errors; npm test 388 passed;
cargo test 232 + 7.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ashproto ashproto added the skip-build Infra/bootstrap PR: skip release build; may target main directly label Aug 9, 2026
@ashproto
ashproto merged commit 02af5d3 into next Aug 9, 2026
2 checks passed
@ashproto
ashproto deleted the fix/clear-vanished-working-selection branch August 10, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-build Infra/bootstrap PR: skip release build; may target main directly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant