From 85b4ba7f362da2f2a918901aa5e79803a1f36cc3 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 24 Nov 2023 13:48:13 -0500 Subject: [PATCH] fix: dispose previous route or outlet before rendering new one (closes #2070) --- router/src/components/outlet.rs | 1 + router/src/components/routes.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/router/src/components/outlet.rs b/router/src/components/outlet.rs index 82c3e6999a..87392a3810 100644 --- a/router/src/components/outlet.rs +++ b/router/src/components/outlet.rs @@ -52,6 +52,7 @@ pub fn Outlet() -> impl IntoView { prev_disposer.flatten() } (Some(child), _) => { + drop(prev_disposer); is_showing.set(Some(child.id())); let (outlet, disposer) = build_outlet(child); set_outlet.set(Some(outlet)); diff --git a/router/src/components/routes.rs b/router/src/components/routes.rs index deee4d1526..5ce76a8e7e 100644 --- a/router/src/components/routes.rs +++ b/router/src/components/routes.rs @@ -484,11 +484,11 @@ fn root_route( if prev.is_none() || !root_equal.get() { root.as_ref().map(|route| { - let (outlet, disposer) = outlet((*route).clone()); - drop(std::mem::replace( + drop(std::mem::take( &mut *root_disposer.borrow_mut(), - Some(disposer), )); + let (outlet, disposer) = outlet((*route).clone()); + *root_disposer.borrow_mut() = Some(disposer); outlet }) } else {