Skip to content

fix(github): align PR file diff order - #10081

Merged
nwparker merged 1 commit into
stablyai:mainfrom
xianjianlf2:fix/pr-files-changed-order-9485
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
xianjianlf2:fix/pr-files-changed-order-9485

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

fix(github): align PR file diff order

Summary

Fixes the desktop GitHub PR "Files changed" view so the diff sections render in the same order as the left-hand file tree.

ELI5

When you review a pull request, the list of files on the left and the actual diffs on the right were in different orders, so clicking a file could jump you to an unexpected spot. Now they line up.

Root cause & fix

The file tree ordered entries via the source-control tree (directories grouped, path-sorted, DFS), but the diff sections consumed the raw GitHub API response order, so the two sequences diverged. This adds getCombinedDiffBranchEntriesInTreeOrder() to combined-diff-file-tree-model.ts, which builds, compacts, and flattens the source-control tree to emit combined-diff entries in file-tree order. Both PR combined-diff viewers (GitHubItemDialog.tsx and PullRequestPage.tsx) now wrap files.map(gitHubPRFileToBranchEntry) with this ordering for mode 'commit'.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Test file: src/renderer/src/components/editor/CombinedDiffFileTree.test.ts
  • On branch: PASS — 1 file, 7 tests passed.
  • Fix reverted (test kept): FAIL on "orders commit entries to match the file tree" — TypeError: getCombinedDiffBranchEntriesInTreeOrder is not a function (1 failed | 6 passed). Proven both ways.
  • Lint: oxlint on the 3 changed source files exits 0, clean.
On branch:  Test Files 1 passed (1) | Tests 7 passed (7)
Reverted:   FAIL "orders commit entries to match the file tree"
            TypeError: getCombinedDiffBranchEntriesInTreeOrder is not a function
            (1 failed | 6 passed)

Trade-offs

None — pure fix.

Regression risk

Low. The change only reorders how already-rendered combined-diff entries are displayed, and the new function reuses the established source-control-tree builders. Non-affected paths are unchanged. Residual note: the test covers the model function directly, not the .tsx viewer wiring — but that wiring is a mechanical wrap of the same call in both files.


Original fix by @xianjianlf2. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c833bd09-0391-4fdb-909c-404be399501f

📥 Commits

Reviewing files that changed from the base of the PR and between 4178b253e18998e4157ee15e5110d979355a7c79 and 5b900d6.

📒 Files selected for processing (4)
  • src/renderer/src/components/GitHubItemDialog.tsx
  • src/renderer/src/components/PullRequestPage.tsx
  • src/renderer/src/components/editor/CombinedDiffFileTree.test.ts
  • src/renderer/src/components/editor/combined-diff-file-tree-model.ts
📝 Walkthrough

Walkthrough

Combined diff viewers now order mapped pull request files through source-control tree traversal. A new helper supports commit and branch modes by building, compacting, flattening, and filtering the tree to file entries. The GitHub item dialog and pull request page use this helper for commit-mode viewers. A unit test verifies the resulting file order.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the fix and evidence, but it misses required template sections like Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing template sections, including Screenshots, a checklist-style Testing section, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes match #9485 by ordering PR diff entries with the same tree traversal and adding a regression test.
Out of Scope Changes check ✅ Passed The PR stays focused on diff ordering and a regression test; no unrelated changes are evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title concisely describes the main change: aligning PR file diff order.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker force-pushed the fix/pr-files-changed-order-9485 branch from 4178b25 to 5b900d6 Compare July 23, 2026 11:49
@nwparker

Copy link
Copy Markdown
Contributor

Before/after evidence (requested by maintainer — not merging yet, for review).

This is a pure ordering change (no visual/styling delta), so the faithful before/after is the file-ordering itself:

PR #10081 — align PR "Files changed" diff order with the file tree

PR: fix(github): align PR file diff order (branch fix/pr-files-changed-order-9485)
Rebased onto current origin/main: efe996a007 (clean)

What changed

The left-hand file tree in the desktop GitHub PR view orders entries via the
source-control tree (directories grouped, path-sorted, depth-first). The diff
sections on the right previously consumed the raw GitHub API response order,
so the two lists diverged. The PR adds
getCombinedDiffBranchEntriesInTreeOrder('commit', …) and wraps
files.map(gitHubPRFileToBranchEntry) in both viewers
(GitHubItemDialog.tsx, PullRequestPage.tsx) so the diff order now matches the
tree order. The new model function reuses the exact same
buildSourceControlTree('combined-commit', …) → compact → flatten pipeline the
file tree already uses (CombinedDiffFileTree.tsx lines 71-73), so alignment is
guaranteed by construction.

BEFORE / AFTER ordering (empirical)

Produced by running the actual ordering function against two datasets.
BEFORE = raw API order (main behavior). AFTER = file-tree order (PR behavior).

Dataset A — unit-test fixture

# BEFORE (main, raw API order) AFTER (PR, file-tree order)
1 src/zebra.ts docs/guide.md
2 README.md src/alpha.ts
3 src/alpha.ts src/zebra.ts
4 docs/guide.md README.md

Dataset B — realistic PR file set

# BEFORE (main, raw API order) AFTER (PR, file-tree order)
1 src/renderer/src/components/PullRequestPage.tsx docs/STYLEGUIDE.md
2 package.json src/main/git.ts
3 src/renderer/src/components/GitHubItemDialog.tsx src/renderer/src/components/editor/combined-diff-file-tree-model.ts
4 docs/STYLEGUIDE.md src/renderer/src/components/GitHubItemDialog.tsx
5 src/main/git.ts src/renderer/src/components/PullRequestPage.tsx
6 CHANGELOG.md CHANGELOG.md
7 src/renderer/src/components/editor/combined-diff-file-tree-model.ts package.json

Note the AFTER order groups directories first (docs/, src/…) with nested folders
sorted depth-first, and floats root-level files (CHANGELOG.md, package.json) to
the end — exactly what the file tree renders.

Test proof (both directions)

  • On PR branch: CombinedDiffFileTree.test.ts → Test Files 1 passed, Tests 7 passed.
  • Fix reverted (model file → main, test kept): FAIL on
    "orders commit entries to match the file tree" —
    TypeError: getCombinedDiffBranchEntriesInTreeOrder is not a function
    (1 failed | 6 passed).

Caveat on "screenshots"

This is a pure data-ordering change with no visual/styling delta, so the
meaningful before/after is the ordering itself (tables above), captured from the
real function. A pixel screenshot would require launching Electron against a live
GitHub PR with a diverging API order; the ordering lists above are the faithful
representation of what the user sees in the "Files changed" panel.

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