Skip to content

fix(code-review): order diff review files to match the changes file tree#3736

Draft
adboio wants to merge 2 commits into
mainfrom
posthog-code/diff-review-match-file-tree-order
Draft

fix(code-review): order diff review files to match the changes file tree#3736
adboio wants to merge 2 commits into
mainfrom
posthog-code/diff-review-match-file-tree-order

Conversation

@adboio

@adboio adboio commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

In the diff review panel, files scroll past in a different order than they appear in the changes file tree beside it, so the two views disagree as you navigate.

Why

The review list rendered files in raw git-diff order (byte/ASCII sort — uppercase paths first), while the changes tree sorts with localeCompare and groups a directory's contents together. Untracked files also dumped at the end of "Changes" in the review instead of interleaving by path like the tree does. So Beta.txt/ZETA_CAPS.txt jumped to the top in the review but sat mid-list in the tree.

Changes

  • Extract the changes tree's build / compact / flatten logic into a shared pure helper in @posthog/core/git-interaction/changeTree (buildChangeTree, compactChangeTree, flattenChangeTree, plus orderPathsLikeChangeTree and a generic sortByChangeTreeOrder).
  • ChangesTreeView now imports the shared tree builders instead of defining its own, so the tree and the review share one source of truth for ordering.
  • The review list (local staged group, the merged unstaged+untracked "Changes" group, and the remote/branch/PR list) is now sorted to mirror the tree's leaf order by construction.

How did you test this?

  • New unit tests for the shared helper (14) covering case-insensitive sort, directory grouping, untracked interleave, and single-child compaction.
  • New unit tests for the review ordering wrappers (6).
  • Existing code-review (45) and task-detail (67) suites still green.

Created with PostHog Code

The diff review panel listed files in git-diff order (byte/ASCII sort:
uppercase first) while the changes file tree beside it sorts with
localeCompare and groups directory contents together, so the two views
diverged as you scrolled. Untracked files also clustered at the end of
"Changes" in the review instead of interleaving by path like the tree.

Extract the tree's build/compact/flatten logic into a shared
@posthog/core helper and have both the changes tree and the review list
consume it, so the review mirrors the tree's leaf order (staged group
and the merged unstaged+untracked "Changes" group) by construction.

Generated-By: PostHog Code
Task-Id: 4eb23888-6afa-4fb9-9b7a-22d6a48e1721
@trunk-io

trunk-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit b5907d7.

@posthog

posthog Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

👋 Visual changes detected for this PR.

Review and approve in PostHog Visual Review

If these changes are unexpected, they may be caused by a flaky test or a broken snapshot on master. Don't approve — rerun the job or wait for a fix.

…irection

Cleanup pass on the diff-review-matches-file-tree change:

- Extract orderedTreeDirs/orderedTreeFiles into the shared changeTree
  helper and have both flattenNode (review ordering) and ChangesTreeView
  (the rendered tree) consume them. The two surfaces now share one
  traversal, so they can't drift on sort order again — the original bug.
- Drop the orderPathsLikeTree/sortReviewItemsByTreeOrder re-export
  aliases from reviewItemBuilders; ReviewPage imports the core helpers
  directly. Removes a layer of indirection with no consumer relying on
  the renamed names.
- Drop the unused TreeNode/buildChangesTree/compactTree back-compat
  aliases from ChangesTreeView; it uses the core names directly.

Net -73 lines; behavior unchanged.

Generated-By: PostHog Code
Task-Id: 4eb23888-6afa-4fb9-9b7a-22d6a48e1721
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.

1 participant