fix(tree): make findNode/getParentNode null-tolerant - #2425
Merged
openai0229 merged 3 commits intoAug 3, 2026
Merged
Conversation
Tree store actions pass get().treeData! into findNode/getParentNode, but treeData is legitimately null (initial, getTreeData, clearTreeStore). The functions dereferenced tree.length with no guard -> null.length NPE on rename/delete/close-connection right after login or during a refresh. Guard the loop with 'tree &&' so a null tree yields undefined instead of throwing. Signatures unchanged to avoid call-site type ripple. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: liuhy <liuhongyu@apache.org>
There was a problem hiding this comment.
Pull request overview
Fixes a frontend tree-store crash by making tree traversal helpers resilient to treeData === null during initial load / refresh windows, preventing null.length runtime errors.
Changes:
- Add null guards to
getParentNode’s iteration to avoid dereferencingtree.lengthwhentreeDatais null. - Add null guards to
findNode’s iteration for the same null-tree scenario.
Suppressed comments (1)
chat2db-community-client/src/utils/index.ts:396
- The recursive branch calls
getParentNode(key, node.children)twice, which doubles the traversal work for every branch and makes the logic harder to read. Cache the recursive result in a local variable and reuse it.
if (node.children.some((item) => item.key === key)) {
finalNode = node;
} else if (getParentNode(key, node.children)) {
finalNode = getParentNode(key, node.children);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
# Conflicts: # chat2db-community-client/package.json
openai0229
approved these changes
Aug 3, 2026
openai0229
left a comment
Contributor
There was a problem hiding this comment.
Reviewed after the nullable-contract and call-site fixes. The focused lookup tests, affected-file ESLint, and full Community frontend build pass locally.
This was referenced Aug 3, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Tree store actions can run while
treeDatais legitimatelynullduring initialization, refresh, or after clearing the store. The previous lookup helpers dereferenced the tree and also claimed a non-null return type even when a node was not found.Fix
treeNodeLookup.ts.TreeNodeData | undefinedfromfindNodeandgetParentNode.splice(-1, 1)when the target datasource is absent.Verification
yarn test:tree-node-lookupyarn test:tree-data-updateyarn build:web:communityFixes #2424