Send mount event when hydrating (#1764)

This commit is contained in:
Hampus Lidin authored and GitHub committed 2023-12-30 13:53:12 -06:00
1 parent 3733fbf47d
commit 0166eafafb
2 files changed
+14 -1

No files matched your search

+5 -1
View File
@@ -256,6 +256,11 @@ impl WebsysDom {
i.flush(); i.flush();
for id in to_mount { for id in to_mount {
self.send_mount_event(id);
}
}
pub(crate) fn send_mount_event(&self, id: ElementId) {
let node = get_node(id.0 as u32); let node = get_node(id.0 as u32);
if let Some(element) = node.dyn_ref::<Element>() { if let Some(element) = node.dyn_ref::<Element>() {
let data: MountedData = element.into(); let data: MountedData = element.into();
@@ -269,7 +274,6 @@ impl WebsysDom {
} }
} }
} }
}
// todo: some of these events are being casted to the wrong event type. // todo: some of these events are being casted to the wrong event type.
// We need tests that simulate clicks/etc and make sure every event type works. // We need tests that simulate clicks/etc and make sure every event type works.
+9
View File
@@ -125,6 +125,7 @@ impl WebsysDom {
children, attrs, .. children, attrs, ..
} => { } => {
let mut mounted_id = None; let mut mounted_id = None;
let mut should_send_mount_event = true;
for attr in *attrs { for attr in *attrs {
if let dioxus_core::TemplateAttribute::Dynamic { id } = attr { if let dioxus_core::TemplateAttribute::Dynamic { id } = attr {
let attribute = &vnode.dynamic_attrs[*id]; let attribute = &vnode.dynamic_attrs[*id];
@@ -134,6 +135,9 @@ impl WebsysDom {
let name = attribute.name; let name = attribute.name;
if let AttributeValue::Listener(_) = value { if let AttributeValue::Listener(_) = value {
let event_name = &name[2..]; let event_name = &name[2..];
match event_name {
"mounted" => should_send_mount_event = true,
_ => {
self.interpreter.new_event_listener( self.interpreter.new_event_listener(
event_name, event_name,
id.0 as u32, id.0 as u32,
@@ -142,8 +146,13 @@ impl WebsysDom {
} }
} }
} }
}
}
if let Some(id) = mounted_id { if let Some(id) = mounted_id {
set_node(hydrated, id, current_child.clone()?); set_node(hydrated, id, current_child.clone()?);
if should_send_mount_event {
self.send_mount_event(id);
}
} }
if !children.is_empty() { if !children.is_empty() {
let mut children_current_child = current_child let mut children_current_child = current_child