fix(file-tree): 修复切换仓库后目录树展开状态丢失的问题#338
Merged
J3n5en merged 2 commits intoJ3n5en:mainfrom Mar 5, 2026
Merged
Conversation
修复折叠逻辑,当用户折叠一个包含多个子目录的父节点时,现在会同时清除该目录及其所有展开的后代路径。这防止了孤立的子路径残留在 localStorage 中,导致用户在切换仓库回来后看到子节点显示为"展开"状态但内容为空的现象。 变更: - 简化折叠逻辑:移除复杂的 collectCompactedPaths 递归函数 - 改为直接清除目标路径及所有以其开头的后代路径 - 此行为对压缩链(single-child directories)仍然有效,因为它们本质上就是后代关系 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
|
Claude finished @lwt-sadais's task in 1m 18s —— View job 🔍 代码审查报告
📊 审查概览 · 一目了然
🏆 代码质量评分📋 问题分布🎯 变更分析本次 PR 修改了 变更要点:
修复效果: - // Before: collectCompactedPaths 只沿单子目录链向下收集
- // 多子目录场景下 /a/b、/a/c 等路径残留在 expandedPaths
+ // After: 直接遍历 expandedPaths,删除所有以 path/ 开头的后代
+ for (const p of [...newExpanded]) {
+ if (p === path || p.startsWith(`${path}/`)) {
+ newExpanded.delete(p);
+ }
+ }✅ 审查亮点
🐛 问题清单与修复指南📋 👆 点击此处展开详细问题列表 (共 1 个问题) · 一键复制追踪 📌⚡ 轻微级别 (Minor)
|
| 🎯 优先级 | 🚨 严重 | ⚡ 轻微 | 📈 总计 | |
|---|---|---|---|---|
| 🔴 P0 | 0 个 | - | - | 0 个 |
| 🟡 P1 | - | 0 个 | - | 0 个 |
| 🔵 P2 | - | - | 1 个 | 1 个 |
| 📊 合计 | 0 | 0 | 1 | 1 个 |
🎯 合并决策建议
📋 合并评估结果
| 📊 评估维度 | ⭐ 得分 | 🎯 状态 | 💭 说明 |
|---|---|---|---|
| 🔐 安全性 | 10/10 | ✅ 通过 | 无安全风险,纯前端状态管理逻辑 |
| 📊 代码质量 | 9/10 | ✅ 优秀 | 代码简洁,逻辑清晰,注释规范 |
| ⚡ 性能影响 | 9/10 | ✅ 无影响 | 路径前缀匹配复杂度合理 |
| 🛠️ 功能完整性 | 10/10 | ✅ 完整 | 覆盖多子目录和 compact chain 两种场景 |
| 🧪 测试覆盖 | 7/10 | 无自动化测试,但变更属于 bug 修复且逻辑简单 |
📈 综合评分: 45/50 分 · 等级: 优秀
🚦 最终建议
✅ 建议合并
📝 详细理由:
- 🟢 根因分析准确,修复方案正确且覆盖范围更广
- 🟢 代码量净减少 23 行,复杂度显著降低
- 🟢 与项目中已有的路径清理模式(
refreshNodeChildren)保持一致- 🟢 无安全风险,无性能退化
- 🟢 注释使用英文,符合项目规范
🎯 后续版本可选改进:
- 可选:
- 考虑直接遍历 Set 替代展开为数组(P2,微优化)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
在目录树中展开多层文件夹后,收起父节点(或某个祖先节点),切换到其他仓库再切换回来,目录树的展开状态丢失。
具体表现:
expandedPaths和localStorage中restoreChildren尝试恢复这些孤立路径,但因父节点未展开而静默失败根因分析
collectCompactedPaths仅处理压缩链(单个子目录的连续路径):当父节点有多个子目录时,只删除父节点路径,子节点路径作为孤立路径残留在 localStorage 中。修复方案
将折叠逻辑从"仅移除 compact chain 路径"改为移除目标路径及其所有后代展开路径:
行为对比
代码变更
collectCompactedPaths递归函数(29 行)🤖 Generated with Claude Code