diff --git a/leptos_reactive/src/runtime.rs b/leptos_reactive/src/runtime.rs index 8e36f2552..127b39cef 100644 --- a/leptos_reactive/src/runtime.rs +++ b/leptos_reactive/src/runtime.rs @@ -418,7 +418,7 @@ impl RuntimeId { with_runtime(self, |runtime| { let id = { runtime.scopes.borrow_mut().insert(Default::default()) }; let scope = Scope { runtime: self, id }; - let disposer = ScopeDisposer(Box::new(move || scope.dispose())); + let disposer = ScopeDisposer(scope); (scope, disposer) }) .expect( @@ -439,7 +439,7 @@ impl RuntimeId { } let scope = Scope { runtime: self, id }; let val = f(scope); - let disposer = ScopeDisposer(Box::new(move || scope.dispose())); + let disposer = ScopeDisposer(scope); (val, id, disposer) }) .expect("tried to run scope in a runtime that has been disposed") diff --git a/leptos_reactive/src/scope.rs b/leptos_reactive/src/scope.rs index a0f96e754..46b2636aa 100644 --- a/leptos_reactive/src/scope.rs +++ b/leptos_reactive/src/scope.rs @@ -336,7 +336,8 @@ pub(crate) enum ScopeProperty { /// 1. dispose of all child `Scope`s /// 2. run all cleanup functions defined for this scope by [on_cleanup](crate::on_cleanup). /// 3. dispose of all signals, effects, and resources owned by this `Scope`. -pub struct ScopeDisposer(pub(crate) Box); +#[repr(transparent)] +pub struct ScopeDisposer(pub(crate) Scope); impl ScopeDisposer { /// Disposes of a reactive [Scope](crate::Scope). @@ -345,8 +346,9 @@ impl ScopeDisposer { /// 1. dispose of all child `Scope`s /// 2. run all cleanup functions defined for this scope by [on_cleanup](crate::on_cleanup). /// 3. dispose of all signals, effects, and resources owned by this `Scope`. + #[inline(always)] pub fn dispose(self) { - (self.0)() + self.0.dispose() } }