Match on more places for asset reloading

This commit is contained in:
Jonathan Kelley committed 2024-03-13 15:10:44 -07:00
1 parent 8d8e7edb82
commit 3d699e7a75
9 files changed
+32 -22

No files matched your search

+15 -1
View File
@@ -2,6 +2,7 @@ use crate::{cfg::ConfigOptsServe, BuildResult, Result};
use dioxus_cli_config::CrateConfig;
use cargo_metadata::diagnostic::Diagnostic;
use dioxus_core::Template;
use dioxus_hot_reload::HotReloadMsg;
use dioxus_html::HtmlCtx;
use dioxus_rsx::hot_reload::*;
@@ -25,7 +26,20 @@ pub struct HotReloadState {
pub messages: broadcast::Sender<HotReloadMsg>,
/// The file map that tracks the state of the projecta
pub file_map: Arc<Mutex<FileMap<HtmlCtx>>>,
pub file_map: SharedFileMap,
}
type SharedFileMap = Arc<Mutex<FileMap<HtmlCtx>>>;
impl HotReloadState {
pub fn all_templates(&self) -> Vec<Template> {
self.file_map
.lock()
.unwrap()
.map
.values()
.flat_map(|v| v.templates.values().copied())
.collect()
}
}
/// Sets up a file watcher.
+8 -18
View File
@@ -27,20 +27,9 @@ async fn hotreload_loop(mut socket: WebSocket, state: HotReloadState) -> anyhow:
log::info!("🔥 Hot Reload WebSocket connected");
// update any rsx calls that changed before the websocket connected.
log::info!("🔮 Finding updates since last compile...");
let templates = state
.file_map
.lock()
.unwrap()
.map
.values()
.flat_map(|v| v.templates.values().copied())
.collect::<Vec<_>>();
println!("previously changed: {:?}", templates);
for template in templates {
// These templates will be sent down immediately so the page is in sync with the hotreloaded version
// The compiled version will be different from the one we actually want to present
for template in state.all_templates() {
socket
.send(Message::Text(serde_json::to_string(&template).unwrap()))
.await?;
@@ -65,16 +54,17 @@ async fn hotreload_loop(mut socket: WebSocket, state: HotReloadState) -> anyhow:
let Ok(msg) = msg else { break };
println!("msg: {:?}", msg);
match msg {
HotReloadMsg::UpdateTemplate(template) => {
Message::Text(serde_json::to_string(&template).unwrap())
}
HotReloadMsg::UpdateAsset(asset) => {
Message::Text(format!("asset: {}", asset.display()))
Message::Text(format!("reload-asset: {}", asset.display()))
}
HotReloadMsg::Shutdown => {
log::info!("🔥 Hot Reload WebSocket shutting down");
break;
}
HotReloadMsg::Shutdown => todo!(),
}
};
+3
View File
@@ -277,6 +277,9 @@ impl App {
dioxus_hot_reload::HotReloadMsg::Shutdown => {
self.control_flow = ControlFlow::Exit;
}
// todo: enable asset hotreloading in desktop
dioxus_hot_reload::HotReloadMsg::UpdateAsset(_) => {}
}
}
+1
View File
@@ -184,6 +184,7 @@ impl Driver for DioxusRenderer {
dioxus_hot_reload::HotReloadMsg::Shutdown => {
std::process::exit(0);
}
_ => {}
}
}
});
@@ -63,6 +63,7 @@ where
}
}
#[cfg(feature = "web")]
#[inline]
fn kick_future<F, T>(user_fut: F)
where
+1
View File
@@ -35,6 +35,7 @@ impl Default for HotReloadState {
dioxus_hot_reload::HotReloadMsg::Shutdown => {
std::process::exit(0);
}
_ => {}
}
});
+1 -1
View File
@@ -21,7 +21,7 @@ pub enum HotReloadMsg {
/// A template has been updated
UpdateTemplate(Template),
/// A template has been updated
/// An asset discovered by rsx! has been updated
UpdateAsset(PathBuf),
/// The program needs to be recompiled, and the client should shut down
+2
View File
@@ -218,6 +218,8 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li
dioxus_hot_reload::HotReloadMsg::UpdateTemplate(new_template) => {
vdom.replace_template(new_template);
}
// todo: enable hotreloading in liveview
dioxus_hot_reload::HotReloadMsg::UpdateAsset(_) => {}
dioxus_hot_reload::HotReloadMsg::Shutdown => {
std::process::exit(0);
},
@@ -243,8 +243,6 @@ impl<Ctx: HotReloadingContext> FileMap<Ctx> {
collect_assetlike_attrs(node, &mut asset_urls);
}
println!("asset urls: {:?}", asset_urls);
asset_urls
}