Skip to content

fix(client): promote file tree node to directory when path is both file and directory prefix - #453

Merged
yoshiko-pg merged 1 commit into
yoshiko-pg:mainfrom
shimpeiws:fix/file-tree-node-promotion-452
Aug 7, 2026
Merged

fix(client): promote file tree node to directory when path is both file and directory prefix#453
yoshiko-pg merged 1 commit into
yoshiko-pg:mainfrom
shimpeiws:fix/file-tree-node-promotion-452

Conversation

@shimpeiws

Copy link
Copy Markdown
Contributor

Summary

  • Fix buildFileTree to promote an existing leaf node to a directory when a later file uses the same path as a directory prefix
  • When a diff contains e.g. vendor (deleted file) and vendor/lib.ts (added file), the tree now correctly shows both entries

Fixes #452

Test plan

  • Added test: path exists both as a file and a directory prefix — children are visible
  • All existing tests pass (pnpm test — 840 passed)
  • pnpm check and pnpm build pass

@shimpeiws
shimpeiws force-pushed the fix/file-tree-node-promotion-452 branch 2 times, most recently from b1d9ba1 to 7132fb8 Compare August 6, 2026 06:14
@yoshiko-pg

Copy link
Copy Markdown
Owner

Thanks for the fix! One issue with the promotion approach: a promoted node is rendered only as a directory in renderTreeNode, so the file row for the deleted vendor entry disappears from the tree. You lose click-to-scroll, the reviewed checkbox, and the comment count for that file. The test passes because getByTitle('vendor') matches the directory header title. The reverse order (vendor/lib.ts first, then vendor) also drops the file, since the existing directory node never gets file assigned.

An alternative that handles both orders and keeps the file row: treat the file and the directory as separate sibling nodes by matching on kind in the lookup, e.g. current.children.find((c) => c.name === part && c.isDirectory === !isLast). Note the directory node would then need a distinct React key since both nodes share the path vendor.

…le and directory prefix

When a diff contains a path as both a standalone file (e.g. a deleted
symlink) and a directory prefix (e.g. new files under the same name),
buildFileTree created the node as a leaf on first encounter and never
promoted it to a directory. Children were silently hidden in the tree.

Fixes yoshiko-pg#452
@shimpeiws
shimpeiws force-pushed the fix/file-tree-node-promotion-452 branch from 7132fb8 to 71dcbe9 Compare August 6, 2026 23:23
@shimpeiws

Copy link
Copy Markdown
Contributor Author

@yoshiko-pg

Thanks for the review! Updated to the sibling node approach as you suggested.

Changes:

  • buildFileTree: Added c.isDirectory === !isLast to the find condition so that a file node and a directory node with the same name coexist as separate siblings. Removed the promotion else if block entirely.
  • renderTreeNode: Changed file row key to file:${file.path} to avoid duplicate React keys when both nodes exist.
  • Test: Strengthened to verify that vendor appears as a clickable data-file-row element (not just a directory header) and that onScrollToFile is called on click.

@yoshiko-pg

Copy link
Copy Markdown
Owner

@shimpeiws Thank you!!

寿司ゆき:cool

@yoshiko-pg
yoshiko-pg merged commit 33a17c5 into yoshiko-pg:main Aug 7, 2026
3 checks passed
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.

File tree hides children when a path appears both as a file and a directory prefix

2 participants