Skip to content

Commit

Permalink
fix: Custom elements patching, Add El::is_custom()
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKavik committed Jan 4, 2020
1 parent 95feb0a commit f0d7b97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[unreleased]

- (placeholder)
- Added method `El::is_custom(&self)`.
- Fixed custom elements patching (#325).

## v0.5.1
- [BREAKING] `MessageMapper::map_message` changed to `MessageMapper::map_msg`.
Expand Down
4 changes: 2 additions & 2 deletions examples/server_integration/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/virtual_dom/node/el.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ impl<Ms> El<Ms> {
child.strip_ws_nodes_from_self_and_children();
}
}

/// Is it a custom element?
pub fn is_custom(&self) -> bool {
// @TODO: replace with `matches!` macro once stable
if let Tag::Custom(_) = self.tag {
true
} else {
false
}
}
}

/// Allow the user to clone their Els. Note that there's no easy way to clone the
Expand Down
3 changes: 2 additions & 1 deletion src/virtual_dom/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ fn patch_el<'a, Ms, Mdl, ElC: View<Ms>, GMs>(
// old el vdom's elements are still attached.

// Namespaces can't be patched, since they involve create_element_ns instead of create_element.
// Custom elements can't be patched, because we need to reinit them (Issue #325). (@TODO is there a better way?)
// Something about this element itself is different: patch it.
if old.tag != new.tag || old.namespace != new.namespace {
if old.tag != new.tag || old.namespace != new.namespace || old.is_custom() {
let old_el_ws = old.node_ws.as_ref().expect("Missing websys el");

// We don't use assign_nodes directly here, since we only have access to
Expand Down

0 comments on commit f0d7b97

Please # to comment.