Skip to content

Bug: Trees client paths is required even when given preparedInput #670

@theopak

Description

@theopak

Prerequisites

  • I have searched for duplicate or closed issues
  • I have read the contributing guidelines

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions