fix(files): 在途层渲染 loading 行,消除新展开文件夹的空目录闪烁(#789 移植到 loadLevels 新形状)

移植 PR #789 的语义到 v0.24.1(98a446b)重写后的加载形状,原 diff 基于
已不存在的 loadDir 形状,不再适用:

- 核心条件原样保留:renderLevel 对「未请求」(undefined)与「在途标记」
  (loadLevels 非强制路径写入的 {} —— 无 entries 无 error)都画 loading
  行。修复前标记落进 entries ?? [] 渲染零行:展开新目录闪「loading →
  看似又折叠了 → 条目」,且首挂载的根层也是空体。settled 层必带 entries
  (不可读层另带 error),条件不会误伤真实数据。
- 原 PR 改在 per-level loadDir 请求时代;现形状 loadLevels 非强制路径先
  storeLevel(path, {}) 再发批量 fs.trees,在途标记形状未变,故只需渲染
  侧一处扩展,加载逻辑零改动(force 路径保留旧行的语义不受影响)。
- 测试 tests/file-tree-loading.spec.tsx 随形状移植:原版 gate 住单层
  fsTree 路由,现 gate 住批量 fsTrees 的 { levels } envelope;并按真实
  用户流拆成两批——先挂载根层、落地后再展开子目录触发第二批(批量语义
  本身由 file-tree-batch-load.spec.tsx 单独守护)。三个用例语义不变:
  展开期间 loading 行不消失、真空目录渲染零行不卡 loading、整批失败出
  错误行。判别性验证:回退修复后前两用例红(错误路径用例两态都绿,它
  守护边界而非本次回归)。
- 原 PR 未新增词典 key(复用既有 t('loading')),本次同样零词典改动,
  无需触碰 19 份第三语言词典。
- 全套件对照:改动前后均 1485 通过 / 6 失败;6 个失败(locales ja 缺
  2 key、plugin-meta 打包、tasks-model ×4)在干净 origin/main @1499502
  上同样复现,属 main 既有问题,与本提交无关。
This commit is contained in:
HuanLinOTO committed 2026-10-01 17:15:49 +08:00
1 parent 1499502bfa
commit e10510f29a
2 files changed
+225 -1

No files matched your search

+9 -1
View File
@@ -1528,7 +1528,15 @@ export function FileTree(props: {
const renderLevel = (dir: string, depth: number): ReactNode => {
const level = data[dir]
const head = newFolder?.dir === dir ? renderNewFolderRow(dir, depth) : null
if (level === undefined) {
// Both the not-yet-requested level (`undefined`) and the in-flight marker
// `loadLevels` stores (`{}` — no entries, no error yet) draw the loading
// row. Without the second half the marker fell into `entries ?? []` and
// rendered an EMPTY level (zero rows), so expanding a fresh folder flashed
// "loading row → nothing under the folder (looks collapsed again) →
// entries" for the whole request — and a fresh mount showed a blank body
// under the root row. A settled level always carries `entries` (an
// unreadable one carries `error` too), so this never misfires.
if (level === undefined || (level.entries === undefined && level.error === undefined)) {
return (
<>
{head}