Skip to content

Commit 5c89657

Browse files
committed
fix: Custom elements patching, Add El::is_custom()
1 parent ff258a2 commit 5c89657

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
[unreleased]
44

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

78
## v0.5.1
89
- [BREAKING] `MessageMapper::map_message` changed to `MessageMapper::map_msg`.

examples/server_integration/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/virtual_dom/node/el.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ impl<Ms> El<Ms> {
201201
child.strip_ws_nodes_from_self_and_children();
202202
}
203203
}
204+
205+
/// Is it a custom element?
206+
pub fn is_custom(&self) -> bool {
207+
// @TODO: replace with `matches!` macro once stable
208+
if let Tag::Custom(_) = self.tag {
209+
true
210+
} else {
211+
false
212+
}
213+
}
204214
}
205215

206216
/// Allow the user to clone their Els. Note that there's no easy way to clone the

src/virtual_dom/patch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ fn patch_el<'a, Ms, Mdl, ElC: View<Ms>, GMs>(
127127
// old el vdom's elements are still attached.
128128

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

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

0 commit comments

Comments
 (0)