fix(desktop): stop the file tree throwing when a lookup walks through a file
Problem
The Files tab's tree model throws Unknown directory child index for node N out of ordinary path lookups: getItem, isExpanded, the scroll helper, and the selection remap inside resetPaths during a refresh. N differs every time, so Sentry files each occurrence as a new issue — four so far on this message (DESKTOP-19G, DESKTOP-KR, DESKTOP-P5, DESKTOP-P4), plus DESKTOP-11E's 158 events that #6789 wrapped at one call site. Six events on current builds in the three weeks since that wrapper landed, at three other call sites.
When it throws mid-resetPaths the controller is left half-reset (store swapped, subscription dropped, projection stale) until the next refresh.
Root cause
@pierre/trees' segment walk (findNodeIdBySegments) resolves a/b/c by reading the child index of the node reached so far, without checking that the node is a directory. When the tree holds a/b as a file and the leaf name c exists anywhere else in the tree, the walk reaches the file node and getDirectoryIndex throws. getPathInfo is documented to return null for a path the store does not hold; this is the one shape where it doesn't.
The Files tab produces that shape whenever a directory it has loaded comes back from a listing as a non-directory (a dangling symlink, or a directory replaced by a file between listings — the DESKTOP-19G breadcrumbs show the child listing failing right before the throw) while a row beneath it is still selected. Reproduced against the installed 1.0.0-beta.5; 1.0.0-beta.6 carries the same code, so upgrading would not fix it.
Fix
patches/@pierre%2Ftrees@1.0.0-beta.5.patch: one line infindNodeIdBySegments— return null when the node reached so far is not a directory. Every path-keyed query then answers "not held" for a path beneath a file.- Guard test
apps/desktop/src/pierre-trees-lookup-patch.test.ts, perpatches/README.md(fails when the patch stops applying — verified by stripping the line and rerunning). - Drop
lookupDirectory, the try/catch wrapper #6789 added for the same throw at one call site; it is dead once the library answers null, and its test asserted the throw. - README entry for the patch.
Verification
$ bunx biome check <5 changed source files>
Checked 5 files in 17ms. No fixes applied.
$ cd apps/desktop && bun run typecheck
$ tsc --noEmit (clean)
$ cd apps/desktop && bun test src/pierre-trees-lookup-patch.test.ts src/renderer/.../FilesTab
36 pass
0 fail
Ran 36 tests across 5 files. [101.00ms]
# negative check: strip the patched line from node_modules, rerun guard, restore
error: Unknown directory child index for node 4
(fail) @pierre/trees lookup-through-file patch > getItem answers null for a path beneath a file
Reproduction through the controller before/after the patch (selected row beneath a directory that came back as a file, leaf name recurring elsewhere): resetPaths threw Unknown directory child index for node 4 before; after, it completes and drops the stale selection.
Refs DESKTOP-19G
Summary by cubic
Stops the Files tab file tree from throwing Unknown directory child index when a lookup walks through a node held as a file. The patched @pierre/trees now returns null for paths beneath a file, matching the lookup contract, and the workaround wrapper at one call site is removed.
Bug Fixes
- Patches
@pierre/trees@1.0.0-beta.5sofindNodeIdBySegmentsreturns null when the current node is not a directory. - Removes
lookupDirectoryand its try/catch wrapper since every path-keyed query now answers "not held". - Adds a guard test that fails if the patch stops applying after a version bump.
Summary by CodeRabbit
-
Bug Fixes
- Fixed file tree path lookups that could fail when a path attempted to continue through a file. These paths now resolve safely as unavailable, while valid file and folder paths continue to work correctly.
- Improved reliability when renaming folders by ensuring expanded folders are refreshed as expected.
-
Documentation
- Added documentation describing the file tree path lookup fix and its verification.