Skip to content

useTreeData getItem for the child returns undefined after moving the parent node #8097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gensakusiya opened this issue Apr 15, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@gensakusiya
Copy link

Provide a general summary of the issue here

The getItem() function returns undefined for each child in the moved parent node within the root.

🤔 Expected Behavior?

The getItem() function returns the child after moving the parent node.

😯 Current Behavior

getItem() returns undefined

💁 Possible Solution

Add all removed children in nodeMap for the moved node in the moving function (probably here)

🔦 Context

No response

🖥️ Steps to Reproduce

const tree = useTreeData({
  initialItems: [
    {
       id: 1,
       children: [],
     },
     {
        id: 2,
        children: [],
     },
     {
        id: 3,
        children: [
          {
             id: 30,
             children: [],
          },
          {
             id: 31,
             children: [],
          },
        ],
     },
  ],
  getKey: (item) => item.id,
  getChildren: (item) => item.items,
});

tree.getItem(31) // return node:31
tree.move(3, null, 0)
tree.getItem(31) // return undefined

Version

react-stately: 3.36.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@snowystinger
Copy link
Member

Thanks, I was able to reproduce in a unit test, I've fixed it in #7854 which should be pulled into our tree drag and drop pr

@snowystinger snowystinger added the bug Something isn't working label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants