Skip to content

Commit

Permalink
fix: drop child key on removal in Option and skip allocating Nodes fo…
Browse files Browse the repository at this point in the history
…r ()
  • Loading branch information
matthunz committed Dec 5, 2024
1 parent f743a1d commit e46a859
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ impl<C: Compose> Compose for Option<C> {
rt.pending.borrow_mut().push_back(key);
}
} else if let Some(key) = child_key.get() {
child_key.set(None);

drop_node(&mut nodes, key);
}
}
Expand All @@ -129,6 +131,8 @@ fn drop_node(nodes: &mut SlotMap<DefaultKey, Rc<Node>>, key: DefaultKey) {
parent.children.borrow_mut().retain(|&x| x != key);
}

//Runtime::current().pending.borrow_mut().retain(|&x| x != key);

let children = node.children.borrow().clone();
for key in children {
drop_node(nodes, key)
Expand Down Expand Up @@ -321,10 +325,6 @@ where
}

unsafe fn any_compose(&self, state: &ScopeData) {
if typeid::of::<C>() == typeid::of::<()>() {
return;
}

// Reset the hook index.
state.hook_idx.set(0);

Expand Down Expand Up @@ -354,6 +354,10 @@ where

let child = C::compose(cx);

if child.data_id() == typeid::of::<()>() {
return;
}

let child: Box<dyn AnyCompose> = Box::new(child);
let mut child: Box<dyn AnyCompose> = unsafe { mem::transmute(child) };

Expand Down

0 comments on commit e46a859

Please sign in to comment.