From c3c09de1ba8d2f65593222524d1fb626257f688a Mon Sep 17 00:00:00 2001 From: Kaan Date: Mon, 19 Oct 2026 17:43:31 +0300 Subject: [PATCH] Fix children being unparented after moving to another parent --- src/implicit_effect.luau | 6 +++--- test/tests.luau | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/implicit_effect.luau b/src/implicit_effect.luau index 6fed9bc..402abb7 100644 --- a/src/implicit_effect.luau +++ b/src/implicit_effect.luau @@ -62,7 +62,7 @@ local function update_children_effect(p: { push_cleanup(assert(get_scope()), function() for child in node.cache.cur_children_set do - child.Parent = nil + if child.Parent == p.instance then child.Parent = nil end end end) end @@ -71,7 +71,7 @@ local function update_children_effect(p: { process_child(new_children) for child in cur_children_set do - child.Parent = nil -- unparent all children that weren't in the new children set + if child.Parent == p.instance then child.Parent = nil end -- unparent all children that weren't in the new children set end table.clear(cur_children_set) -- clear cache, preserve capacity @@ -116,7 +116,7 @@ return { push_cleanup(assert_stable_scope(), function() for child in node.cache.cur_children_set do - child.Parent = nil + if child.Parent == instance then child.Parent = nil end end end) diff --git a/test/tests.luau b/test/tests.luau index cd9cd1d..39a5cd0 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1050,6 +1050,33 @@ TEST("create()", wrap_root(function() CHECK(parent:FindFirstChild "c") end + do CASE "children moved to another parent" + local other = create "Frame" {} + + local child = create "Frame" {} + local children_a = source { child } + local children_b = source {} + create "Frame" { children_a } + local parent_b = create "Frame" { children_b } + + children_b { child } + children_a {} + CHECK(child.Parent == parent_b) + + local a = create "Frame" {} + local b = create "Frame" {} + local destroy = root(function() + create "Frame" { function() return a end } + create "Frame" { function() return { function() return b end } end } + end) + + a.Parent = other + b.Parent = other + destroy() + CHECK(a.Parent == other) + CHECK(b.Parent == other) + end + do CASE "garbage collection test" local wref