Skip to content

fix(ui): preserve root dir state when sibling dir is expanded#2393

Open
trivikr wants to merge 4 commits intonpmx-dev:mainfrom
trivikr:fix/source-tree-expansion
Open

fix(ui): preserve root dir state when sibling dir is expanded#2393
trivikr wants to merge 4 commits intonpmx-dev:mainfrom
trivikr:fix/source-tree-expansion

Conversation

@trivikr
Copy link
Copy Markdown
Contributor

@trivikr trivikr commented Apr 5, 2026

🔗 Linked issue

resolves #2363

🧭 Context

The package code sidebar was re-expanding a collapsed sibling directory when another directory in the same tree was opened. On ky@1.14.3, collapsing core/ and then expanding types/ caused both directories to appear expanded again.

This change fixes the tree expansion logic so only the intended directory opens, and adds coverage for the regression.

📚 Description

The root cause was that the code tree auto-expanded the current file path from recursive CodeFileTree instances, not just from the root tree. That meant a subtree remount could re-apply ancestor expansion and reopen a directory the user had just collapsed.

This PR:

  • limits auto-expansion of the current file path to the root file tree instance
  • keeps file tree expansion state updates explicit by replacing the stored Set after mutations
  • adds a Nuxt regression test covering the sibling-directory case from the issue

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 10, 2026 10:18pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 10, 2026 10:18pm
npmx-lunaria Ignored Ignored Apr 10, 2026 10:18pm

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 875b840c-f99e-4440-8b8c-92c64d20ca3c

📥 Commits

Reviewing files that changed from the base of the PR and between c4d8f05 and f13968d.

📒 Files selected for processing (3)
  • app/components/Code/FileTree.vue
  • app/composables/useFileTreeState.ts
  • test/nuxt/components/CodeFileTree.spec.ts
✅ Files skipped from review due to trivial changes (2)
  • app/components/Code/FileTree.vue
  • test/nuxt/components/CodeFileTree.spec.ts

📝 Walkthrough

Walkthrough

Changed FileTree auto-expansion so autoExpandAncestors(path) runs only when depth.value === 0 and currentPath is non-empty, preventing nested recursive CodeFileTree instances from triggering ancestor expansion. In useFileTreeState.ts, after mutating expanded sets in toggleDir and autoExpandAncestors, the code now reassigns expanded.value = new Set(expanded.value) to force reactivity. Added a Vitest for CodeFileTree that verifies expand/collapse and active-path behaviour.

Suggested reviewers

  • danielroe
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the bug in tree expansion logic and detailing the specific changes made to fix it.
Linked Issues check ✅ Passed The pull request directly addresses issue #2363 by limiting auto-expansion to the root instance, preventing unintended re-expansion of sibling directories when users expand another directory.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the reported issue: FileTree watcher logic, expansion state management, and regression test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fb276bf-51e8-4d8d-a8c7-d5b8cd6fdb78

📥 Commits

Reviewing files that changed from the base of the PR and between 5324b96 and c4d8f05.

📒 Files selected for processing (3)
  • app/components/Code/FileTree.vue
  • app/composables/useFileTreeState.ts
  • test/nuxt/components/CodeFileTree.spec.ts

@serhalp serhalp added the needs review This PR is waiting for a review from a maintainer label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you take a look at the other review comments too?

trivikr added 3 commits April 10, 2026 14:49
- Recompute expanded state after toggling or auto-expanding directories
- Only auto-expand ancestors for the top-level tree
- Add regression coverage for sibling directory expansion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review This PR is waiting for a review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source tree-view expands 2 directories instead of 1

5 participants