Skip to content

fix(tree): guard updateTreeData against null list - #2423

Merged
openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/tree-updatetreedata-null-guard-2422
Aug 3, 2026
Merged

openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/tree-updatetreedata-null-guard-2422

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

A tree refresh can set treeData to null while a previously-started lazy load settles. updateTreeData previously dereferenced the null value and crashed the tree view.

Fix

  • Move the pure tree update helper into a focused module.
  • Accept the real nullable tree contract.
  • Preserve null so the UI remains in its loading state during the race.
  • Keep recursive child updates array-valued.
  • Add regression coverage for null input, nested replacement, child count, and immutability.
  • Run the new test from the Community prebuild.

Verification

  • yarn test:tree-data-update
  • targeted ESLint
  • git diff --check

Fixes #2422

updateTreeData did list.map(...) with no null guard. getTreeData/clearTreeStore
null out treeData, and handleLoadData passes the (possibly null) origin into
setTreeData, so a refresh racing a lazy-load threw null.map and crashed the
tree view. Guard with Array.isArray and return [].

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: liuhy <liuhongyu@apache.org>
@Aias00
Aias00 requested a review from openai0229 as a code owner August 3, 2026 12:27
Copilot AI review requested due to automatic review settings August 3, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a crash in the community client tree store where updateTreeData could throw null.map during a refresh/lazy-load race, taking down the tree view.

Changes:

  • Added a runtime guard in updateTreeData to avoid calling .map() on a null/invalid list.
  • Documented the race scenario inline to explain why the guard is necessary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread chat2db-community-client/src/store/tree/index.tsx Outdated

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed after merging the latest main and fixing the loading-state regression. Null is preserved, nested updates remain immutable, focused regression tests pass, targeted ESLint passes, and the test is part of the Community prebuild.

@openai0229
openai0229 merged commit 3a72dc7 into OtterMind:main Aug 3, 2026
20 of 21 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(tree): updateTreeData throws null.map when refresh races a lazy-load

3 participants