Files
apes-sidebar/tests
HuanLinOTO 5256eef3ab fix(files): 目录级别加载失败不再被当成缓存命中,自动加载路径可重试(#677 移植到 loadLevels 新形状)
PR #677 was written against the pre-0.24.1 loadDir shape (one fs.tree per
directory): its error branch stored { error } in the level cache and the
cache-hit guard `dataRef.current[dir] !== undefined` treated that failure as
"already loaded", so the automatic load path never re-requested a failed
level; only the force path (refresh tick / fence-notice retry) recovered.

FileTree.tsx has since been rewritten around batched loadLevels (one fs.trees
POST for the visible set, commit 98a446b), but the bug survived the rewrite in
a new spot: BOTH failure branches now store an error in the same cache —
(a) a per-level `error` riding an otherwise-successful batch, and
(b) `{ error }` written by the whole-request catch for levels with no listing
    — and the non-force `wanted` filter (`dataRef.current[path] === undefined`)
counted both as cache hits.

Port, in current idioms:

- The non-force filter now admits a cached entry only when it carries no
  `error`: `cached === undefined || cached.error !== undefined`. The host
  guarantees a failed level never carries entries (fs.trees returns
  `{ entries: [], error }` in place), so `error` alone identifies "nothing
  usable cached" for both failure branches.
- The empty `{}` placeholder of an in-flight load is still a hit, so a
  re-render while a batch is open does not duplicate the request.
- The retry rides the batch route (wanted subset only; levels that DID list
  stay cached) and reuses the existing non-force flow, which stores `{}`
  first — same behavior the original fix gave loadDir.
- loadLevels' doc comment gains the "only a LISTING settles a level" rule.

Not ported: the original diff's comment wording about "the fence notice's
retry button" — that notice (and isOutsideWorkspaceMessage usage in the tree)
no longer exists in the current shape; recovery paths today are the refresh
tick and watch-notice/mutation re-lists, and after this fix any automatic
re-load of the expanded set.

Tests: tests/file-tree-level-retry.spec.tsx adapts the PR's spec to the
batched shape (fsTrees mock, batch-load-spec harness): (1) a per-level error
is re-requested as a batch of 1 on the next automatic load (with an added
assertion that an in-flight batch is NOT duplicated), (2) levels stored by a
failed whole request are all retryable. Both go red on the unfixed filter
(verified: "expected to be called 2 times, but got 1"). All 9 file-tree
suites (47 tests) and tsc --noEmit stay green.
2026-10-01 17:13:10 +08:00
..
2026-09-09 11:15:30 +08:00