Skip to content

Commit

Permalink
Clone the root in Document::from_data_model_instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Sep 19, 2023
1 parent 0c969c5 commit 5507136
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/roblox/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,20 @@ impl Document {

let mut dom = WeakDom::new(DomInstanceBuilder::new("ROOT"));

for data_model_child in i.get_children() {
data_model_child.clone_into_external_dom(&mut dom);
// We want to clone the entire DataModel into a new dom. To correctly preserve Ref
// properties, we'll have to first call clone_into_external_dom on the root...
let cloned_root = i.clone_into_external_dom(&mut dom);

// ...then transfer its children to the new root (the unwrap is safe because
// clone_into_external_dom always inserts the cloned instance into the destination
// dom)...
for child in dom.get_by_ref(cloned_root).unwrap().children().to_owned() {
dom.transfer_within(child, dom.root_ref())
}

// ...and then get rid of the cloned root.
dom.destroy(cloned_root);

postprocess_dom_for_place(&mut dom);

Ok(Self {
Expand Down

0 comments on commit 5507136

Please sign in to comment.