Skip to content

bug(tree): findNode/getParentNode throw on null treeData #2424

Description

@Aias00

Description

Tree store actions (deleteAiDataCollection, deleteAiDataCollectionElement, updateTreeNodeDataByKey, closeConnection, updateOriginalTitleByNodeId, getChildrenByNodeId) pass get().treeData! into findNode/getParentNode. treeData is legitimately null (initial value, getTreeData, clearTreeStore null it). findNode/getParentNode dereference tree.length with no null guard → null.length NPE. The ! non-null assertions at call sites mask the nullable type.

Location

chat2db-community-client/src/utils/index.ts:384-397 (getParentNode), :425-438 (findNode); call sites src/store/tree/index.tsx:501,526,568,655,669,678.

Impact

Rename/delete/close-connection actions NPE when treeData is null (e.g. right after login or during a refresh).

Suggested fix

Make findNode/getParentNode null-tolerant (guard if (!tree || !tree.length) return undefined; and drop the ! on the return), so a null tree yields undefined instead of throwing. Single-point fix covering all call sites.

Related existing

None.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions