Skip to content

Commit

Permalink
move node erasure to construction
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldSEnder committed May 15, 2022
1 parent cbabe59 commit 258cc3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions packages/yew/src/dom_bundle/btag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ impl Reconcilable for VTag {
BTagInner::Other { child_bundle, tag }
}
};
let node_ref = node_ref.to_erased();

node_ref.set_erased::<Node>(el.clone().into());
(
Expand Down Expand Up @@ -230,7 +229,7 @@ impl Reconcilable for VTag {
tag.key = self.key;
let el: Node = el.clone().into();

let next_node_ref = self.node_ref.to_erased();
let next_node_ref = self.node_ref;
if tag.node_ref != next_node_ref {
// See the comment in `detach` why we don't unconditionally set to None here
if tag.node_ref.get_node().as_ref() == Some(&el) {
Expand Down Expand Up @@ -372,7 +371,6 @@ mod feat_hydration {
};

let el_node: Node = el.clone().into();
let node_ref = node_ref.to_erased();
node_ref.set_erased::<Node>(el_node.clone());

(
Expand Down
1 change: 1 addition & 0 deletions packages/yew/src/html/html_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl<T: 'static> HtmlRef<T> {
Some(self.get_ref()?.clone())
}

#[inline]
pub(crate) fn to_erased(&self) -> ErasedHtmlRef {
ErasedHtmlRef {
place: self.inner.clone() as Rc<RefCell<dyn Any>>,
Expand Down
7 changes: 4 additions & 3 deletions packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::rc::Rc;
use web_sys::{HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement};

use super::{AttrValue, Attributes, Key, Listener, Listeners, VList, VNode};
use crate::html::{IntoPropValue, NodeRef};
use crate::html::{ErasedHtmlRef, IntoPropValue, NodeRef};

/// SVG namespace string used for creating svg elements
pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg";
Expand Down Expand Up @@ -124,7 +124,8 @@ pub struct VTag {
/// List of attached listeners.
pub(crate) listeners: Listeners,
/// A node reference used for DOM access in Component lifecycle methods
pub node_ref: NodeRef,
#[cfg_attr(not(feature = "csr"), allow(dead_code))]
pub(crate) node_ref: ErasedHtmlRef,
/// List of attributes.
pub attributes: Attributes,
pub key: Option<Key>,
Expand Down Expand Up @@ -254,7 +255,7 @@ impl VTag {
inner,
attributes,
listeners,
node_ref,
node_ref: node_ref.to_erased(),
key,
}
}
Expand Down

0 comments on commit 258cc3a

Please sign in to comment.