Fix double node removal (#983)

* Fix double node removal

* Fix clippy
This commit is contained in:
Justin Starry 2020-03-01 19:16:04 +08:00 committed by GitHub
parent 86af481c0d
commit bb7c8280a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -161,19 +161,13 @@ enum Reform {
}
impl VDiff for VComp {
fn detach(&mut self, parent: &Element) -> Option<Node> {
fn detach(&mut self, _parent: &Element) -> Option<Node> {
let mut replace_state = MountState::Detached;
swap(&mut replace_state, &mut self.state);
match replace_state {
MountState::Mounted(this) => {
(this.destroyer)();
this.node_ref.get().and_then(|node| {
let next_sibling = node.next_sibling();
parent
.remove_child(&node)
.expect("can't remove the component");
next_sibling
})
this.node_ref.get().and_then(|node| node.next_sibling())
}
_ => None,
}

View File

@ -3,6 +3,7 @@
use super::{VChild, VComp, VDiff, VList, VTag, VText};
use crate::html::{Component, Renderable};
use cfg_if::cfg_if;
use log::warn;
use std::cmp::PartialEq;
use std::fmt;
use std::iter::FromIterator;
@ -39,9 +40,9 @@ impl VDiff for VNode {
VNode::VList(ref mut vlist) => vlist.detach(parent),
VNode::VRef(ref node) => {
let sibling = node.next_sibling();
parent
.remove_child(node)
.expect("can't remove node by VRef");
if parent.remove_child(node).is_err() {
warn!("Node not found to remove VRef");
}
sibling
}
}