diff --git a/tachys/src/html/element/mod.rs b/tachys/src/html/element/mod.rs
index c4fc742296..10676adbb2 100644
--- a/tachys/src/html/element/mod.rs
+++ b/tachys/src/html/element/mod.rs
@@ -443,12 +443,22 @@ impl Deref for ElementState {
impl Mountable for ElementState
where
+ Ch: Mountable,
R: Renderer,
{
fn unmount(&mut self) {
+ if let Some(children) = self.children.as_mut() {
+ children.unmount_from_parent();
+ }
R::remove(self.el.as_ref());
}
+ fn unmount_from_parent(&mut self) {
+ if let Some(children) = self.children.as_mut() {
+ children.unmount_from_parent();
+ }
+ }
+
fn mount(&mut self, parent: &R::Element, marker: Option<&R::Node>) {
R::insert_node(parent, self.el.as_ref(), marker);
}
diff --git a/tachys/src/view/mod.rs b/tachys/src/view/mod.rs
index 9e349ee86e..a121a95670 100644
--- a/tachys/src/view/mod.rs
+++ b/tachys/src/view/mod.rs
@@ -282,6 +282,15 @@ pub trait Mountable {
/// Detaches the view from the DOM.
fn unmount(&mut self);
+ /// Detaches the view from the DOM, when it is a child of another element that is being
+ /// unmounted.
+ ///
+ /// Most elements do not require any action here, but special view types that have additional
+ /// unmount logic do.
+ fn unmount_from_parent(&mut self) {
+ self.unmount();
+ }
+
/// Mounts a node to the interface.
fn mount(&mut self, parent: &R::Element, marker: Option<&R::Node>);
diff --git a/tachys/src/view/primitives.rs b/tachys/src/view/primitives.rs
index 025aa88e0e..e267bd041a 100644
--- a/tachys/src/view/primitives.rs
+++ b/tachys/src/view/primitives.rs
@@ -27,6 +27,8 @@ macro_rules! render_primitive {
self.0.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,
diff --git a/tachys/src/view/strings.rs b/tachys/src/view/strings.rs
index 73266e8b65..09f1f93f66 100644
--- a/tachys/src/view/strings.rs
+++ b/tachys/src/view/strings.rs
@@ -131,6 +131,8 @@ where
self.node.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,
@@ -232,6 +234,8 @@ impl Mountable for StringState {
self.node.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,
@@ -324,6 +328,8 @@ impl Mountable for RcStrState {
self.node.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,
@@ -427,6 +433,8 @@ impl Mountable for ArcStrState {
self.node.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,
@@ -530,6 +538,8 @@ impl<'a, R: Renderer> Mountable for CowStrState<'a, R> {
self.node.unmount()
}
+ fn unmount_from_parent(&mut self) {}
+
fn mount(
&mut self,
parent: &::Element,