From f969d77da8e28a04e844b1c051896e9b3e1e0ecb Mon Sep 17 00:00:00 2001 From: Ash Shah <494shah@gmail.com> Date: Sun, 9 Aug 2026 15:28:37 -0700 Subject: [PATCH] fix: show the empty state when the selected file leaves the working copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 --- src/lib/components/WorkingCopyView.svelte | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/components/WorkingCopyView.svelte b/src/lib/components/WorkingCopyView.svelte index 3113e9a..9ac6c0f 100644 --- a/src/lib/components/WorkingCopyView.svelte +++ b/src/lib/components/WorkingCopyView.svelte @@ -104,8 +104,13 @@ // monotonic revision counter (workingChangesRev) instead of the file count so that // a hunk stage/unstage — which doesn't change the file count but does re-index // hunks on the backend — also triggers a re-fetch and prevents stale hunk indices. + // `section` is 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. Keying on `selectedFile` + // alone kept the key non-empty there and fetched an unstaged diff for a file with nothing + // to diff: no row could highlight (the row test already requires a matching section), while + // the pane showed an empty diff instead of the nothing-selected state. const diffKey = $derived( - selectedFile !== null + selectedFile !== null && section !== null ? `${selectedFile}::${section}::${selectedIsUntracked}::${appState.workingChangesRev}::${appState.effectiveDiffContext}` : "", ); @@ -570,7 +575,9 @@
- {#if !selectedFile} + + {#if !selectedFile || section === null}

Select a file to view its diff.

{:else if diffLoading}

Loading diff…