fix(staged): select first file from sidebar order instead of raw git order#717
Conversation
…order When a diff opens, the initial file selection used `state.files[0]` from the raw git response (sorted by full path), which could differ from the first file shown in the sidebar (sorted per-directory with dirs first). Add a reactive effect in DiffModal that overrides the initial selection with `orderedFiles[0]` once files finish loading, keeping the viewer and sidebar in sync. The flag resets on context switches so it re-fires for new file sets. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bafae077e3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!diffViewer.state.loading && orderedFiles.length > 0 && !initialSelectionApplied) { | ||
| initialSelectionApplied = true; | ||
| diffViewer.selectFile(orderedFiles[0].path); |
There was a problem hiding this comment.
Wait for review state before locking initial selection
When opening an existing non-readonly review, reviewHandle.state.reviewedPaths is populated asynchronously by createReviewState, but this effect marks initialSelectionApplied as soon as diff files finish loading. If the review load resolves after diffViewer.state.loading becomes false, orderedFiles is still computed with every file as needs-review, so a file that is already reviewed can be selected and the later reviewed-path update cannot correct it because the flag is already true. This still leaves the initial file out of sync with the needs-review → reviewed sidebar order for saved reviews with reviewed files.
Useful? React with 👍 / 👎.
When opening an existing review, the initial file selection effect fired as soon as diff files loaded, before reviewedPaths finished loading from the backend. This meant orderedFiles was computed with all files in the needs-review bucket, so the selected file could differ from the actual sidebar order once reviewed paths arrived. Add a guard that also waits for reviewHandle.state.loading to be false before applying the initial selection, ensuring the needs-review vs reviewed split is accurate when picking the first file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
Summary
Test plan
🤖 Generated with Claude Code