Skip to content

Fix: Re-parent pulled-up directory children to ensure proper checkbox refresh#8679

Open
MaxDNG wants to merge 2 commits intomicrosoft:mainfrom
MaxDNG:fix/folder-checkbox-parent-reparenting
Open

Fix: Re-parent pulled-up directory children to ensure proper checkbox refresh#8679
MaxDNG wants to merge 2 commits intomicrosoft:mainfrom
MaxDNG:fix/folder-checkbox-parent-reparenting

Conversation

@MaxDNG
Copy link
Copy Markdown

@MaxDNG MaxDNG commented Apr 20, 2026

Fixes #8646

This pull request addresses a bug where directory tree nodes that are promoted to the parent node (when the root directory label is empty) were not correctly updating their parent references. The changes ensure that child nodes have their parent property set correctly when they are moved up in the tree. This improves the consistency and correctness of the tree structure in the UI.

Tree node parenting fixes:

  • In commitNode.ts, when flattening root directory nodes, each child’s parent is now set to the current node before being promoted to the parent.
  • In filesCategoryNode.ts, after flattening root directory nodes, each child’s parent is set to the current node to maintain correct parent relationships.
  • In pullRequestNode.ts, when promoting children of a root directory node, each child’s parent is set appropriately before being added to the parent.

MaxDNG added 2 commits April 20, 2026 15:50
… refresh

When the tree has multiple top-level directories, a temporary DirectoryTreeNode
is created to build the tree, then its children are pulled up to the parent.
However, the children's parent pointers still referenced the phantom root,
causing processCheckboxUpdates to refresh an invisible node, so checkbox state
never updated visually.

Re-parent all pulled-up children to the actual container node (FilesCategoryNode,
PullRequestNode, or CommitNode) so ancestor walks target visible tree nodes.
…ilding

Add tests to verify that pulled-up directory children are correctly re-parented
to the container node, not the phantom root. This ensures processCheckboxUpdates
can walk ancestors and find visible tree nodes for refresh() calls.

Tests cover:
- getParent() correctly returns undefined after re-parenting
- ancestor walk stops at topmost visible directory, not phantom root
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a tree-view checkbox refresh bug caused by “phantom root” DirectoryTreeNode instances (label '') retaining parent pointers after their children are promoted to the real container node.

Changes:

  • Re-parent pulled-up directory children to the actual container in PR, commit, and files category tree nodes.
  • Add a regression test covering parent-pointer behavior after phantom-root promotion.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/view/treeNodes/pullRequestNode.ts Re-parents children promoted from a phantom root to the PRNode so checkbox refresh targets visible nodes.
src/view/treeNodes/filesCategoryNode.ts Re-parents children promoted from a phantom root to FilesCategoryNode to keep the rendered hierarchy consistent.
src/view/treeNodes/commitNode.ts Re-parents children promoted from a phantom root to the CommitNode for correct ancestor refresh behavior.
src/test/view/treeNodes/directoryTreeNode.test.ts Adds coverage for parent-chain behavior when a phantom root’s children are pulled up.

Comment on lines +217 to +232
it('getParent() returns undefined after child is re-parented to the container', function () {
const container = createMockParent();
const phantomRoot = new DirectoryTreeNode(container, '');
const subDir = new DirectoryTreeNode(phantomRoot, 'src');

// Before re-parenting: parent is the phantom root DirectoryTreeNode
assert.ok(subDir.getParent() instanceof DirectoryTreeNode, 'sanity: should point to phantom root before re-parenting');

// Simulate the pull-up re-parenting fix applied in filesCategoryNode / pullRequestNode / commitNode
subDir.parent = container;

// After re-parenting: container is not a TreeNode, so getParent() returns undefined.
// This means the ancestor walk in processCheckboxUpdates stops here and refresh()
// is called on the visible subDir node, not the invisible phantom root.
assert.strictEqual(subDir.getParent(), undefined, 'after re-parenting, getParent() should not return the phantom root');
});
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The new test simulates re-parenting to a non-TreeNode container and asserts getParent() becomes undefined. In the production fix, the pulled-up children are re-parented to this (e.g., PRNode / CommitNode / FilesCategoryNode), which is a TreeNode, so getParent() should return that container node (and, critically, should no longer return the phantom root). Consider adjusting the test to use a mock TreeNode container and assert that getParent() is not the phantom DirectoryTreeNode (and optionally equals the container), rather than asserting undefined.

Copilot uses AI. Check for mistakes.
@MaxDNG
Copy link
Copy Markdown
Author

MaxDNG commented Apr 20, 2026

@microsoft-github-policy-service agree

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.

Reopening - Parent folder checkbox not auto-checked when all children are marked as viewed

2 participants