From c172914b21211a3196c86ebe75a7b63b7a6a23e0 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 23 Jan 2024 11:40:45 -0600 Subject: [PATCH] drop scopes in order when dropping the virtual dom --- packages/core/src/arena.rs | 2 +- packages/core/src/virtual_dom.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs index ac680299f..602657810 100644 --- a/packages/core/src/arena.rs +++ b/packages/core/src/arena.rs @@ -64,7 +64,7 @@ impl VirtualDom { self.elements.try_remove(el.0).map(|_| ()) } - // Drop a scope and all its children + // Drop a scope without dropping its children // // Note: This will not remove any ids from the arena pub(crate) fn drop_scope(&mut self, id: ScopeId) { diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 864a3c5d5..abfaf3e7f 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -762,7 +762,11 @@ impl VirtualDom { impl Drop for VirtualDom { fn drop(&mut self) { - // Simply drop this scope which drops all of its children - self.drop_scope(ScopeId::ROOT); + // Drop all scopes in order of height + let mut scopes = self.scopes.drain().collect::>(); + scopes.sort_by_key(|scope| scope.context().height); + for scope in scopes.into_iter().rev() { + drop(scope); + } } }