From 56d193d1966691f0acc2078b0142d9d919d8cdc4 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Thu, 22 Dec 2022 11:30:30 -0500 Subject: [PATCH] fix: try to guard against double drop --- packages/core/src/arena.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs index 9d723d89c..a18fa7ad6 100644 --- a/packages/core/src/arena.rs +++ b/packages/core/src/arena.rs @@ -136,8 +136,8 @@ impl VirtualDom { } /// Descend through the tree, removing any borrowed props and listeners - pub(crate) fn ensure_drop_safety(&self, scope: ScopeId) { - let scope = &self.scopes[scope.0]; + pub(crate) fn ensure_drop_safety(&self, scope_id: ScopeId) { + let scope = &self.scopes[scope_id.0]; // make sure we drop all borrowed props manually to guarantee that their drop implementation is called before we // run the hooks (which hold an &mut Reference) @@ -145,8 +145,9 @@ impl VirtualDom { let mut props = scope.borrowed_props.borrow_mut(); props.drain(..).for_each(|comp| { let comp = unsafe { &*comp }; - if let Some(scope_id) = comp.scope.get() { - self.ensure_drop_safety(scope_id); + match comp.scope.get() { + Some(child) if child != scope_id => self.ensure_drop_safety(child), + _ => (), } drop(comp.props.take()); });