fix hot reloading rsx with nested rsx calls
This commit is contained in:
1 parent
6f92e05d64
commit
ef6ae642ba
1 file changed
+26
-20
+26
-20
@@ -57,14 +57,27 @@ pub(crate) fn update_rsx(
|
|||||||
+ ":"
|
+ ":"
|
||||||
+ &line.to_string()
|
+ &line.to_string()
|
||||||
+ ":"
|
+ ":"
|
||||||
+ &column.to_string();
|
+ &column.to_string()
|
||||||
|
// the byte index doesn't matter, but dioxus needs it
|
||||||
|
+ ":0";
|
||||||
|
|
||||||
if let Some(template) = new_call_body.update_template(
|
if let Some(template) = new_call_body.update_template(
|
||||||
Some(old_call_body),
|
Some(old_call_body),
|
||||||
Box::leak(location.into_boxed_str()),
|
Box::leak(location.into_boxed_str()),
|
||||||
) {
|
) {
|
||||||
*template_slot = Some(template);
|
// dioxus cannot handle empty templates
|
||||||
messages.push(template);
|
if template.roots.is_empty() {
|
||||||
|
return UpdateResult::NeedsRebuild;
|
||||||
|
} else {
|
||||||
|
// if the template is the same, don't send it
|
||||||
|
if let Some(old_template) = template_slot {
|
||||||
|
if old_template == &template {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*template_slot = Some(template);
|
||||||
|
messages.push(template);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return UpdateResult::NeedsRebuild;
|
return UpdateResult::NeedsRebuild;
|
||||||
}
|
}
|
||||||
@@ -119,7 +132,6 @@ impl FileMap {
|
|||||||
let result = Self {
|
let result = Self {
|
||||||
map: find_rs_files(path).unwrap(),
|
map: find_rs_files(path).unwrap(),
|
||||||
};
|
};
|
||||||
// log::info!("Files updated");
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,22 +171,16 @@ pub async fn hot_reload_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut rx = state.messages.subscribe();
|
let mut rx = state.messages.subscribe();
|
||||||
let hot_reload_handle = tokio::spawn(async move {
|
loop {
|
||||||
loop {
|
if let Ok(rsx) = rx.recv().await {
|
||||||
if let Ok(rsx) = rx.recv().await {
|
if socket
|
||||||
println!("sending");
|
.send(Message::Text(serde_json::to_string(&rsx).unwrap()))
|
||||||
if socket
|
.await
|
||||||
.send(Message::Text(serde_json::to_string(&rsx).unwrap()))
|
.is_err()
|
||||||
.await
|
{
|
||||||
.is_err()
|
break;
|
||||||
{
|
};
|
||||||
println!("error sending");
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
hot_reload_handle.await.unwrap();
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user