Prerequisites
Describe the issue
resetPaths already has a runtime short-circuit when paths == null && preparedInput != null — it skips the parse + sort validation entirely:
// dist/model/FileTreeController.js — resolveFileTreeInput
if (paths == null) return { paths: preparedPaths, preparedInput };
if (!haveMatchingPaths(PathStore.preparePaths(paths, …), preparedPaths)) throw …;
But the public types make paths required, so a TS caller can't reach that branch without casting:
resetPaths(paths: readonly FileTreePublicId[], options?: FileTreeResetOptions): void;
Result: a caller using preparePresortedFileTreeInput (the scale-oriented path) is forced through PathStore.preparePaths — a full parseInputPath per path plus a sort — which is the exact work preparePresortedFileTreeInput exists to skip. On large trees this dominates resetPaths and makes the presorted API strictly slower than not using preparedInput at all.
Suggested fix
Make paths optional on resetPaths to match the runtime that already supports it:
- resetPaths(paths: readonly FileTreePublicId[], options?: FileTreeResetOptions): void;
+ resetPaths(paths?: readonly FileTreePublicId[], options?: FileTreeResetOptions): void;
(Same change on the FileTreeController overload, readonly string[].)
Reproduction
import { preparePresortedFileTreeInput } from '@pierre/trees';
import { useFileTree } from '@pierre/trees/react';
const folderPaths = ['/a/', '/a/b/', '/c/', '/c/d/']; // server-canonical
const { model } = useFileTree({ paths: [] });
model.resetPaths([], {
preparedInput: preparePresortedFileTreeInput(folderPaths),
});
// Throws: FileTree resetPaths received paths and preparedInput for different path lists
What browser(s) are you seeing the problem on?
Not browser-specific — reproduced on Bun and Node.
What version of @pierre/trees are you using?
1.0.0-beta.3
AI disclosure: issue written with assistance from claude-opus-4.7-xhigh based on usage in my private codebase.
Prerequisites
Describe the issue
resetPathsalready has a runtime short-circuit whenpaths == null && preparedInput != null— it skips the parse + sort validation entirely:But the public types make
pathsrequired, so a TS caller can't reach that branch without casting:Result: a caller using
preparePresortedFileTreeInput(the scale-oriented path) is forced throughPathStore.preparePaths— a fullparseInputPathper path plus a sort — which is the exact workpreparePresortedFileTreeInputexists to skip. On large trees this dominatesresetPathsand makes the presorted API strictly slower than not usingpreparedInputat all.Suggested fix
Make
pathsoptional onresetPathsto match the runtime that already supports it:(Same change on the
FileTreeControlleroverload,readonly string[].)Reproduction
What browser(s) are you seeing the problem on?
Not browser-specific — reproduced on Bun and Node.
What version of @pierre/trees are you using?
1.0.0-beta.3
AI disclosure: issue written with assistance from
claude-opus-4.7-xhighbased on usage in my private codebase.