Skip to content

Move a child out of its old container when it is added to another - #175

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/144-reparent-child
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/144-reparent-child

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #144

What changed

UIContainerBase.AddChild set child.Parent = this without detaching the child from its current container. The child ended up in both containers, rendered twice, and raised Invalidated on both. RemoveChild on the old container then set Parent to null even though the child was still in the new one.

  • AddChild now removes the child from its previous parent before adopting it.
  • RemoveChild and ClearChildren only clear Parent when it still points at this container.

Tests

New UIContainerBaseTests checks the issue's acceptance criteria:

  • After a.AddChild(c); b.AddChild(c);, c is only in b.Children and c.Parent == b.
  • a.RemoveChild(c) returns false and leaves c.Parent as b.
  • The old container is no longer invalidated by the moved child.

All three failed before the fix. The full suite passes with it (212/212).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCL6GX9wshgqiBeq6z98ZH


Generated by Claude Code

…r [patch]

AddChild set Parent without detaching the child from its previous container,
so the child sat in both, and RemoveChild on the old one then nulled Parent
while the child was still in the new one. AddChild now removes the child from
its previous parent first, and RemoveChild/ClearChildren only clear Parent
when it still points at this container.

Fixes #144

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCL6GX9wshgqiBeq6z98ZH
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 914a361 into main Sep 29, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/144-reparent-child branch September 29, 2026 12:48
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.

Adding an element to a second container leaves it in the first too; removing it from the first then nulls its Parent while it's still in the second

1 participant