Skip to content

Fix useTreeData subtree move validation - #10560

Open
su-jin1425 wants to merge 2 commits into
adobe:mainfrom
su-jin1425:fix-usetreedata-move-bug
Open

Fix useTreeData subtree move validation#10560
su-jin1425 wants to merge 2 commits into
adobe:mainfrom
su-jin1425:fix-usetreedata-move-bug

Conversation

@su-jin1425

Copy link
Copy Markdown

Description

Closes #10539

Summary

Prevent useTreeData from silently dropping nodes when an item is moved into its own subtree.

This adds validation to the imperative move, moveBefore, and moveAfter APIs so that moves targeting a node's own descendants throw:

Cannot move an item to be a child of itself.

The validation also covers root-level nodes, which were previously missed by moveBefore and moveAfter.

Changes

  • Added ancestor validation to move().
  • Fixed root-level ancestor validation in moveBefore() and moveAfter().
  • Added isolated regression tests covering nested and root-level self-subtree moves for all three APIs.
  • No changes to drag-and-drop behavior.

Pull Request Checklist:

Test Instructions:

Run the useTreeData test suite:

yarn jest useTreeData

The regression tests verify that move, moveBefore, and moveAfter throw when attempting to move an item into its own subtree, including root-level ancestor cases.

Your Project:

None

@su-jin1425
su-jin1425 force-pushed the fix-usetreedata-move-bug branch from d305b81 to 6bc74bf Compare September 3, 2026 10:45

if (!didThrow) {
expect(console.error).toHaveBeenCalled();
const errorString = console.error.mock.calls.flat().join(' ');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added additional Regression test for safety Tell me if you dont want these.

@su-jin1425
su-jin1425 force-pushed the fix-usetreedata-move-bug branch from 6bc74bf to 0153b79 Compare September 5, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useTreeData: move() silently drops a node moved into its own subtree; moveBefore/moveAfter miss root-level nodes

2 participants