From b09e528aaab2f18274d66d6bc158009c68253fee Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 4 Aug 2023 14:14:56 -0700 Subject: [PATCH] fix recursive runtime drop impl --- packages/core/src/runtime.rs | 8 -------- packages/core/src/virtual_dom.rs | 7 ++++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/core/src/runtime.rs b/packages/core/src/runtime.rs index 7b9c7c05c..839a055df 100644 --- a/packages/core/src/runtime.rs +++ b/packages/core/src/runtime.rs @@ -49,13 +49,6 @@ pub struct Runtime { pub(crate) scope_stack: RefCell>, } -impl Drop for Runtime { - fn drop(&mut self) { - // todo: do this better - pop_runtime(); - } -} - impl Runtime { pub(crate) fn new(scheduler: Rc) -> Rc { let runtime = Rc::new(Self { @@ -65,7 +58,6 @@ impl Runtime { scope_stack: Default::default(), }); - push_runtime(runtime.clone()); runtime } diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 0d22cbeea..1a2cf5c5d 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -9,7 +9,7 @@ use crate::{ mutations::Mutation, nodes::RenderReturn, nodes::{Template, TemplateId}, - runtime::Runtime, + runtime::{pop_runtime, push_runtime, Runtime}, scopes::{ScopeId, ScopeState}, AttributeValue, Element, Event, Scope, }; @@ -275,6 +275,9 @@ impl VirtualDom { // the root element is always given element ID 0 since it's the container for the entire tree dom.elements.insert(ElementRef::none()); + // Set this as the current runtime + push_runtime(dom.runtime.clone()); + dom } @@ -648,5 +651,7 @@ impl Drop for VirtualDom { fn drop(&mut self) { // Simply drop this scope which drops all of its children self.drop_scope(ScopeId(0), true); + // remove the current runtime + pop_runtime(); } }